A component is mounted using render(), and when the parent component's value changes, the child component does not change. #7396
-
使用函数渲染的方式挂载组件,父组件的值变化后,子组件没有相应变化。 A component is mounted using render(), and when the parent component's value changes, the child component does not change. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
Beta Was this translation helpful? Give feedback.
-
The children component is not update is because when use the The core/packages/reactivity/src/baseHandlers.ts Lines 143 to 146 in 588bd44 You can use like this: App.vue <script setup>
import { ref, h, render as r, reactive, watch } from 'vue'
import HelloWorld from "./HelloWorld.vue"
const text = ref("1")
const textObj = reactive({
a:text
})
console.warn(textObj.a, typeof textObj.a)
let vNode = h(HelloWorld, {
modelValue: text
});
setInterval(()=>{
text.value = text.value + '1'
},1000)
const vNodeDom = document.createElement('div')
document.body.appendChild(vNodeDom)
r(vNode, vNodeDom)
</script>
<template>
<div id='a'>
</div>
父组件:{{textObj.a}}
<HelloWorld v-model="textObj.a"/>
</template> |
Beta Was this translation helpful? Give feedback.
The children component is not update is because when use the
textObj.a
, it is astring
not a ref.The
textObj.a
is a string because when get value will return theres.value
As the following source code shows.core/packages/reactivity/src/baseHandlers.ts
Lines 143 to 146 in 588bd44
You can use like this:
playground
App.vue