【发布时间】:2021-01-10 12:24:24
【问题描述】:
我写了一个单文件组件来展示一些东西,这里是代码
<template>
<el-link type="primary" @click="test()" >{{this.contentShow}}</el-link>
</template>
<script lang="ts">
import moment from 'moment'
import {Watch, Prop,Component, Vue } from 'vue-property-decorator'
export default class extends Vue{
@Prop({ default: "111" }) private content!: string
private contentShow = "11";
private test(){
alert("111");
}
@Watch('content')
private contentChange(value: any) {
this.contentShow = value;
console.log(value);
}
}
</script>
我想更改 el-link 的内容,但我失败了。这是代码
<userButton content="tttteeeessssttt"></userButton>
从网站控制台我可以看到没有使用“contentChange”方法。
顺便说一句,我试着这样写:
<el-link type="primary" @click="test()" >{{this.content}}</el-link>
但是说错了
vue.runtime.esm.js:619 [Vue 警告]:属性或方法“内容”未在实例上定义,但在渲染期间引用。
那么有什么问题吗?如何更改组件的内容?
非常感谢。
【问题讨论】:
-
尝试删除内容属性的私有修饰符。
-
我试过了还是不行
标签: javascript html typescript vue.js