1.属性绑定
props传值时,父组件xxx如果使用了:xxx=”333”,那么传入的是数字而不是字符串
:xxx=” ‘helloWorld’ “则是字符串
2.! ?
1.const input = button.textcontent as string;// as 断言,此属性一定为string类型2.const input = button.textcontent!;// 表示input不会为空
type a = {x:string,y?:number //表示y可以必须为number或者string属性}
数组类型
type a = {x:string,y?:numberz: string[] //内部数据一定为string的数组}
双向数据绑定
v-model
<input type="text" :value="x" @input="x= $event.target.value">x=''等于<input type="text" v-model='x'>
.sync
child<button @click="$emit('update:money',money-100)">// update:money中的money并不是一个简单的字符串,vue会根据给定的名称进行分析,// 随便写并不会触发,.sync的子组件与父组件的数据绑定<span>花钱</span></button>props:['money']father<child :money="total" v-on:update:money="total=$event" />total:1000等于<child :money.sync="total"/>如果v-on:update:money="function"如果子向父的自定义事件为一个函数,那么函数第一个参数为传递的数据function(x){} 即x
npx
vite文档给出的命令是
npm init vite-app
yarn create vite- app
等价于
全局安装create-vite-app
然后cva
