[英]Nuxt TypeScript: Cannot assign to 'name' because it is a read-only property
<template lang="pug">
.bd-solid.bdw-1.bdc-teal.p-10.m-10.ta-c
h4.fs-32 📜
p.mt-10 > {{name}}
p.mt-10 > {{reverse()}}
button.fs-24.p-5.mt-10(@click='change') 💱
</template>
<script lang="ts">
import Vue from "vue"
export default Vue.extend({
props: {
name: {
type: String,
default: 'abcd'
}
},
methods: {
reverse() {
return this.name.split('').reverse().join('');
},
change() {
this.name = 'aaa';
}
},
})
</script>
TS2540: Cannot assign to 'name' because it is a read-only property.
56 | },
57 | change() {
> 58 | this.name = 'aaa';
| ^^^^
59 | }
60 | },
61 |
This code as well as the details, what stackoverflow expected code more than details with their auto detect feature?
这段代码以及细节,stackoverflow 期望的代码比它们的自动检测功能的细节更多吗?
I think it's a bad idea to change prop Name inside component, you probably should change it inside another component where this one is used我认为在组件内更改 prop Name 是个坏主意,您可能应该在使用该组件的另一个组件内更改它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.