使用$ref 宏函数 (获取数据不需要.value)

2022-12-14  本文已影响0人  月下小酌_dbd5
vue版本 需要3.2.25 及以上(使用新特性,需要开启配置)
module.exports = defineConfig({
  ...
  chainWebpack: config => {
    // 显示的开启Props解构默认值
    config.module
      .rule('vue')
      .use('vue-loader')
      .tap((options) => {
        return {
          ...options,
          reactivityTransform: true
        }
      })
  },
})

export default defineConfig({
   ...
  plugins: [
    vue({
      reactivityTransform:true
    }),
   vueJsx()],
   ...
})
设置完后就可以直接引用使用了
<script lang="ts" setup>
import { $ref } from "vue/macros"
let name= $ref('')
name = '唐园园'
</script>
解构
<script setup lang='ts'>
import { reactive, toRefs } from 'vue'
import {$} from 'vue/macros'
const user= reactive({
    name: '唐园'
})
 
let { name } = $(user);
name = '汤圆'
</script>
上一篇 下一篇

猜你喜欢

热点阅读