data
<template>
<h3>选项式API</h3>
<p>{{ message }}</p>
</template>
<script>
export default {
data(){
return{
message:"选项式API 绑定数据"
}
}
}
</script>
<template>
<h3>组合式API</h3>
<p>{{ message }}</p>
<p>{{ userInfo.name }}</p>
</template>
<script>
import { ref,reactive } from "vue"
export default {
setup(){
const message = ref("组合式API 绑定数据")
const userInfo = reactive({
name:"iwen"
})
return{
message,
userInfo
}
}
}
</script>
ref和reactive的区别
ref用于创建基本类型响应数据
reactive用于创建引用类型响应数据
<template>
<h3>组合式API</h3>
<p>{{ message }}</p>
<p>{{ userInfo.name }}</p>
</template>
<script setup>
import { ref,reactive } from "vue"
const message = ref("组合式API 绑定数据")
const userInfo = reactive({
name:"iwen"
})
</script>