programing

v-model이 작동하지 않는 이유는 무엇입니까?

copyandpastes 2022. 8. 3. 23:53
반응형

v-model이 작동하지 않는 이유는 무엇입니까?

이건 Vue.js에서의 첫 번째 코드입니다.간단한 온라인 튜토리얼을 따르고 있습니다.vue-cli를 사용하여 애플리케이션을 설치한 후 간단한 구성 요소를 생성했습니다.Test.vue여기에는 내 모델의 메시지 속성에 바인딩된 간단한 입력 컨트롤이 포함되어 있습니다.

Test.vue

<template>
  <div 
    <input 
        type="text" 
        v-model="message"/>
    <br/>
    <p>The value of the input is: {{ message }}</p>
  </div>
</template>

<script>
    export default {  
      data:{
        message: 'My name'
      }
    };
</script>

<style>
</style>

그런 다음 이 컴포넌트를 로드합니다.<App />그런데 입력란에 글을 쓰면<p>요소가 업데이트되지 않았습니다...

여기에 이미지 설명 입력

내가 뭘 잘못하고 있지?이것은 꽤 간단해 보인다.당신의 제안과 올바른 방향을 가르쳐 주셔서 감사합니다.

성분에서 데이터는 함수여야 합니다.

export default {  
  data(){
    return {
      message: 'My name'
    }
  }
};

또한 템플릿에는>첫 번째 div를 썼는데 질문을 쓰면서 그런 일이 있었던 것 같아요.

<template>
  <div>
    <input 
        type="text" 
        v-model="message"/>
    <br/>
    <p>The value of the input is: {{ message }}</p>
  </div>
</template>

언급URL : https://stackoverflow.com/questions/47823702/why-v-model-is-not-working

반응형