diff --git a/src/App.vue b/src/App.vue index 196fb6676242c1ebd82b10666a4a7abab5ae5c0e..21d982f5c0d51da349295b5e68e5c6b89708e24a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,105 +2,26 @@ import Com1 from './components/Com1.vue' import Com2 from './components/Com2.vue' import {onMounted, toRefs,watchEffect,shallowReadonly,readonly,ref,reactive,shallowRef,computed, isRef, unref, toRef, toValue, watch, onBeforeMount, onBeforeUpdate, onUpdated} from 'vue' - -// onBeforeMount(()=>{ -// debugger -// console.log('onBeforeMount') -// }) -// onMounted(()=>{ -// debugger -// console.log('onMounted') -// }) - -// onBeforeUpdate(()=>{ -// debugger -// console.log('onBeforeUpdate') -// }) -// onUpdated(()=>{ -// debugger -// console.log('onUpdated') -// }) -const obj={ - name:'普通obj' +const tabs = { + Com1, + Com2 } -const msg = ref("你好!") - -const refMsg = ref({ - msg:"欢迎使用VUE3.0" -}) -const shallowRefMsg = shallowRef({ - msg:"欢迎使用VUE3.1" -}) - -const refObjMsg = ref({ - msg:ref({ - obj:ref("你好") - }) -}) - -console.log(msg) - -const refCom = ref({ - name:'Com1', - com:Com1 +const currentObj = ref({ + tab:Com1, + key:'Com1' }) -function changeMsg(){ - // refMsg.value = 777 - // refMsg.value.msg = 888 - msg.value += '12' +function changeCom(k,v){ + currentObj.value.key = k + currentObj.value.tab = v } -setTimeout(() => { - changeMsg() -}, 6000); -function changeShallowRefMsg(){ - // shallowRefMsg.value = 888 - shallowRefMsg.value.msg = 999 - console.log(shallowRefMsg) -} - -function useFeature(id){ - watch( - ()=>toValue(id), - (val)=>{ - console.log(77,val) - } - ) -} - -function changeCom(){ - if(refCom.value.name === 'Com1'){ - refCom.value.name = 'Com2' - refCom.value.com = Com2 - }else{ - refCom.value.name = 'Com1' - refCom.value.com = Com1 - } -} -useFeature(refMsg) - -const reactiveObj = reactive(obj) -console.log(reactiveObj) -console.log(obj) -console.log(reactiveObj == obj) -watchEffect(()=>{ - document.body.innerHTML = `msg is: ${msg.value}` -})