简体   繁体   English

Nuxt TypeScript:无法分配给“名称”,因为它是只读属性

[英]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>

How to get rid of this Error?如何摆脱这个错误?

  • I use Nuxt, TypeScript, Pug, Sass.我使用 Nuxt、TypeScript、帕格、Sass。
  • I am new with Nuxt, some syntax and function I may not used to.我是 Nuxt 的新手,有些语法和 function 我可能不习惯。
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.

相关问题 角度无法分配给“名称”,因为它是常量或只读属性 - Angular Cannot assign to 'name' because it is a constant or a read-only property 即使属性未标记为只读,打字稿“无法分配给属性,因为它是常量或只读” - Typescript “Cannot assign to property, because it is a constant or read-only” even though property is not marked readonly 角度2 | 无法分配给数组,因为它是常量或只读属性 - Angular 2 | cannot assign to array because it is a constant or a read-only property 无法分配给“total”,因为它是一个常量或只读属性 - Cannot assign to 'total' because it is a constant or a read-only property TS 2540:无法分配给样式,因为它是只读属性 - TS 2540: Cannot assign to style because it is a read-only property 无法分配给“fromDate”,因为它是只读属性。ts - Cannot assign to 'fromDate' because it is a read-only property.ts 无法分配给“状态”,因为它是常量或只读属性 - Cannot assign to 'state' because it is a constant or a read-only property 无法分配给“ initialState”,因为它是只读属性 - Cannot assign to 'initialState' because it is a read-only property 无法分配给“布尔”,因为它是常量或只读属性 - Cannot assign to 'Boolean' because it is a constant or a read-only property 获取错误:&#39;无法分配到&#39;location&#39;,因为它是一个常量或只读属性&#39;与Angular app中的mailto函数 - Getting error: 'Cannot assign to 'location' because it is a constant or a read-only property' with mailto function in Angular app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM