1.安装插件 cnpm install @vue-macros/reactivity-transform -D
2.vite.config.js引入
// 导入库
import ReactivityTransform from '@vue-macros/reactivity-transform/vite'
export default defineConfig(({ mode, command }) => {
return {
plugins: [
// createVitePlugins(env, command === 'build'),
vue(),
ReactivityTransform(),//对 ref 语法糖进行转化,不用使用.value赋值
setupExtend(),
AutoImport({
imports: ['vue', 'vue-router', 'pinia'], //自动引入vue的ref、toRefs、onmounted等,无需在页面中再次引入
dts: false, // 生成在src路径下名为auto-import.d.ts的声明文件
})
]
}
})
<template>
<div>
<el-button @click="clickBtn">点击</el-button>
{{ count }}
</div>
</template>
<script setup>
let count = $ref(0)
const clickBtn = () => {
count++
console.log('22', count)
}
</script>