这段代码有啥问题,为啥运行不出来

阅读 58

2022-02-23

<!DOCTYPE html>
<div id="v-model-example" class="demo">
   <my-component v-model:title="bookTitle"></my-component>
   {{ bookTitle }}
</div>

<script src="https://unpkg.com/vue@next"></script>
<script>
    const app = Vue.createApp({
      data() {
     return {
         bookTitle: ''
       }
  },
    });
    app.component('my-component', {
  props: {
   modelValue: String,
   modelModifiers: {
             default: () => ({})
             }
  },
  
  emits: ['update:title'],
  template: `
    <input
      type="text"
      :value="modelValue"
      @input="$emit('update:modelValue', $event.target.value)">
      `,
      created() {
    console.log(this.modelModifiers) // { capitalize: true }
  }
   }).mount('#v-model-example')
</script>




改了。有一点改善。

<!DOCTYPE html>
<div id="v-model-example" class="demo">
   <my-component v-model.capitalize="myText"></my-component>
   {{ bookTitle }}
</div>

<script src="https://unpkg.com/vue@next"></script>
<script>
    const app = Vue.createApp({
      data() {
     return {
         bookTitle: ''
       }
  },
    });
    app.component('my-component', {
  props: {
   modelValue: String,
   modelModifiers: {
             default: () => ({})
             }
  },
  
  emits: ['update:modelValue'],
  template: `
    <input
      type="text"
      :value="modelValue"
      @input="$emit('update:modelValue', $event.target.value)">
      `,
      created() {
    console.log(this.modelModifiers) // { capitalize: true }
  }
   }).mount('#v-model-example')
</script>




精彩评论(0)

0 0 举报