vue3 setup语法糖


1. watch监听  watchEffect

import {ref,reactive, watchEffect } from 'vue'

watchEffect(()=>{ console.log('watch', activeTitle.value) })

2. computed计算属性

{{computedValue}}
import {ref,reactive, computed } from 'vue' const computedValue = computed(()=> { return '计算属性' });

3. await数据获取

let tableData = reactive([])
let getList = async ()=>{
      let data = await getTag({type: "ai"}).then(res=>res.data)
      tableData.push(...data)   //vue3使用proxy数组和对象不可以直接赋值
}
onMounted (async() => { 
      getList()
});

4. 组间传参

  父组件





子组件





vue