<h1 @click="str1Change">{{ str1 }}</h1>
<h1 @click="objChange">{{ obj.name }}--{{ obj.age }}</h1>
<h1>{{ str }}</h1>
<hr>
<comp-c></comp-c>
</template>
<script>
import CompC from './components/CompC.vue'
import { computed, reactive, ref, watch,provide } from "vue";
export default {
name: "App",
components:{
CompC
},
setup() {
let str1 = ref("我要谢谢你");
let str2 = ref("因为有你");
let obj = reactive({
name:"张三",
age:30
})
provide('info',obj)
let str = computed(() => {
return str1.value + str2.value;
});
function str1Change() {
str1.value = "春天花会开";
}
function objChange(){
obj.name = '李四'
}
watch(()=>obj.name,()=>{
console.log('name被监听了')
})
return {
str1,
str2,
str,
obj,
str1Change,
objChange
};
},
};