sameVnode的问题
来源:5-7 组件更新(1)
我要学习去了
2021-09-15
我想测试测试一下sameVnode这个方法,然后给组件加了一个v-if,调用方法去改变v-if的值,但是一点击vue就报警告了
警告如下:
vue.esm.js?a026:628 [Vue warn]: Error in v-on handler: "TypeError: Cannot read properties of undefined (reading 'update')"
vue.esm.js?a026:1908 TypeError: Cannot read properties of undefined (reading 'update')
代码如下:
<template>
<div id="app">
<div ref="hahaha" v-if="isShow">{{ msg }}</div>
<div>
<button @click="change">点击</button>
</div>
<Hello>
<template v-slot:test>
<div>插槽</div>
</template>
<template v-slot:person="{ name, age }">
我叫{{ name }},今年{{ age }}岁
</template>
</Hello>
</div>
</template>
<script>
import Hello from "./components/Hello";
export default {
name: "App",
components: { Hello },
data() {
return {
isShow: false,
msg: "what this is",
$str: "这是以$符开头的key",
};
},
methods: {
test() {
console.log("this is test method");
},
change() {
this.isShow = true
this.msg = "值被我改变了"
}
},
created() {
},
};
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>写回答
2回答
-
ustbhuangyi
2021-09-16
你把这个代码传到 GitHub 上,我抽空帮你看看
00 -
我要学习去了
提问者
2021-09-15
但是我change的时候,把下面的
this.msg = "值被我改变了"
注释了,警告和报错就没有看了
00
相似问题
sameVnode 问题
回答 1
加上key的重要性
回答 1