1.属性绑定

props传值时,父组件xxx如果使用了:xxx=”333”,那么传入的是数字而不是字符串
:xxx=” ‘helloWorld’ “则是字符串

2.! ?

  1. 1.const input = button.textcontent as string;
  2. // as 断言,此属性一定为string类型
  3. 2.const input = button.textcontent!;
  4. // 表示input不会为空
  1. type a = {
  2. x:string,
  3. y?:number //表示y可以必须为number或者string属性
  4. }

数组类型

  1. type a = {
  2. x:string,
  3. y?:number
  4. z: string[] //内部数据一定为string的数组
  5. }

双向数据绑定

v-model

  1. <input type="text" :value="x" @input="x= $event.target.value">
  2. x=''
  3. 等于
  4. <input type="text" v-model='x'>

.sync

  1. child
  2. <button @click="$emit('update:money',money-100)">
  3. // update:money中的money并不是一个简单的字符串,vue会根据给定的名称进行分析,
  4. // 随便写并不会触发,.sync的子组件与父组件的数据绑定
  5. <span>花钱</span>
  6. </button>
  7. props:['money']
  8. father
  9. <child :money="total" v-on:update:money="total=$event" />
  10. total:1000
  11. 等于
  12. <child :money.sync="total"/>
  13. 如果v-on:update:money="function"如果子向父的自定义事件为一个函数,那么函数第一个参数为传递的数据
  14. function(x){} x

npx

vite文档给出的命令是
npm init vite-app
yarn create vite- app

等价于
全局安装create-vite-app
然后cva

等价于
npx createa-vite -app
即npx会帮你全局安装用到的包