其实到了vue3 官方所指的耦合 很多成分意思是 希望大家将代码都写在 setup中
<template>
<div style = "padding: 10px;">
{
{ information }}
</div>
</template>
<script>
import {
ref } from 'vue'
export default {
setup(){
const information = ref(13241324)
return {
information
}
}
};
</script>
<style>
</style>
我们就可以将其改成
<template>
<div style = "padding: 10px;">
{
{ information }}
</div>
</template>
<script setup>
import {
ref } from 'vue'
const information = ref(13241324)
</script>
<style>
</style>
效果也是一样的 这样开发 在
<script setup>
中 以const声明的函数 以及reactive ref声明的数据都不需要返回 直接成为响应式数据 可在界面中使用