반응형
Vue 클래스 기반 구성 요소 경고: 속성이 인스턴스에서 정의되지 않고 렌더링 중에 참조됨
나는 vue-class 구성 요소와 typecript를 사용하여 vue 구성 요소를 생성하려고 한다(여기 https://github.com/vuejs/vue-class-component) 참조).내가 이해한 바로는, 데이터는 내가 아래에서 했던 것과 같이 클래스에 정의되어 있다. 그러나 나는 다음과 같은 오류를 받는다.
"[Vue warn]: Property or method "test" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property."
여기 내 실제 코드의 벗겨진 버전이 있지만, 여전히 작동하지 않는다.
<template>
<div id="vue-test">
<input v-model="test"/>
{{test}}
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
@Component({
})
export default class AppearanceDialogVue extends Vue {
public test: string = '100';
}
</script>
편집: '테스트' 선언을 다음으로 변경한 것으로 나타남
public test: string;
일했다
이 문제에 대한 해결책은 다음과 같다. 생성자를 추가하고 생성자에서 속성을 초기화해야 함
<template>
<section class="dropdown" style="background-color: #dde0e3">
<select class="btnList" v-model="foo">
<option v-for="item in selectedfooData" :value="item" :key="item.id">{{item}}</option>
</select>
{{foo}}
</section>
</template>
<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';
@Component
export default class HelloWorld extends Vue {
private foo: string;
private selectedfooData : string[] = [
'one',
'two'
]
construtor() {
super();
this.foo = '';
}
}
</script>
반응형
'Programing' 카테고리의 다른 글
C에서 stderr로 인쇄하려면 어떻게 해야 하는가? (0) | 2022.04.16 |
---|---|
시스템을 언제 불러야 할까?자바로 퇴장하다 (0) | 2022.04.16 |
더블이 NaN과 동일한지 확인하기 위해 어떻게 테스트하는가? (0) | 2022.04.16 |
Vuex 돌연변이 반환이 마지막으로 삽입됨 (0) | 2022.04.15 |
선택 입력 /w Vuex 저장소 바인딩에 의한 동적 구성 요소 (0) | 2022.04.14 |