模版

Vue TSX Admin https://github.com/manyuemeiquqi/vue-tsx-admin

soybean-admin https://github.com/honghuangdc/soybean-admin

构建工具

pnpm: 复用node_module,加速依赖安装 https://pnpm.io/

yarn https://yarnpkg.com/getting-started

前端教程

https://biaoyansu.com/

CSS

盒子模型 margin 外边距:画框外留白 padding 内边距:画框内留白

位置position position属性的默认值为static

position: static;

相对定位:在relative值的基础上设置top、right、left、bottom属性

.relative2 {
  position: relative;
  top: -20px;
  left: 20px;
  background-color: white;
  width: 500px;
}

固定定位:盒子的位置相对于浏览器窗口定位

.fixed {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 200px;
  background-color: white;
}

绝对定位:

.relative {
  position: relative;
  width: 600px;
  height: 400px;
}
.absolute {
  position: absolute;
  top: 120px;
  right: 0;
  width: 300px;
  height: 200px;
}

flexbox flex下的居中布局

.vertical-container {
  height: 300px;
  display: -webkit-flex;
  display:         flex;
  -webkit-align-items: center;
          align-items: center;
  -webkit-justify-content: center;
          justify-content: center;
}

Vue

模板

<template> </template> 变量模板

<span>Message: {{ msg }}</span>

变量绑定标签Attribute

<!--常规变量绑定-->
<div v-bind:id="dynamicId"></div>
<!--布尔型绑定-->
<button :disabled="isButtonDisabled">Button</button>

事件绑定

<a v-on:[eventName]="doSomething"> ... </a>
 
<!-- 简写 -->
<a @[eventName]="doSomething">

条件渲染

<button @click="awesome = !awesome">Toggle</button>
 
<h1 v-if="awesome">Vue is awesome!</h1>
<h1 v-else>Oh no 😢</h1>

列表渲染

<li v-for="item in items">
  {{ item.message }}
</li>

表单输入绑定

<p>Message is: {{ message }}</p>
<input v-model="message" placeholder="edit me" />

组件

在父组件中使用子组件

<script>
import ButtonCounter from './ButtonCounter.vue'
 
export default {
//注册ButtonCounter组件
  components: {
    ButtonCounter
  }
//上列等价于  ButtonCounter: ButtonCounter
}
</script>
 
<template>
  <h1>Here is a child component!</h1>
  <ButtonCounter />
</template>

其中ButtonCounter.vue文件是一个单文件组件SingleFileComponent(SFC) 组件和组件之间变量相互独立,每创建一个新的组件,就相当于创建了一个新的实例

组件中动态Prop

<!-- 根据一个变量的值动态传入 -->
<BlogPost :title="post.title" />
 
<!-- 根据一个更复杂表达式的值动态传入 -->
<BlogPost :title="post.title + ' by ' + post.author.name" />

透传attribute 在组件中写attribute最终会加到模版DOM元素上

插槽 当模板的内容需要动态改变时,可以使用插槽预留空位

<FancyButton>
  Click me! <!-- 插槽内容 -->
</FancyButton>

而FancyButton.vue的内容是这样的

<button class="fancy-btn">
  <slot>
    default value <!-- 默认内容 -->
  </slot> <!-- 插槽出口 -->
</button>

具名插槽 给插槽命名

<div class="container">
  <header>
    <slot name="header"></slot>
  </header>
  <main>
    <slot></slot>
  </main>
  <footer>
    <slot name="footer"></slot>
  </footer>
</div>

使用插槽

<BaseLayout>
  <template v-slot:header>
    <!-- header 插槽的内容放这里 -->
  </template>
</BaseLayout>