Vue在调用组件base-input的时候,无法读出label的值,这是为什么呢?

  <div id="app">
    <base-input v-model="username" required placeholder="Enter your username"></base-input>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

  <script>
    Vue.component('base-input', {
      inheritAttrs: false,
      props: ['label', 'value'],
      template: `
    <label>
      {{ label }}
      <input
        v-bind="$attrs"
        v-bind:value="value"
        v-on:input="$emit('input', $event.target.value)"
      >
    </label>
  `
    });

    new Vue({
      el: "#app",
      data: {
        label: '用户',
        value: '',
        username: ''
      }
    })

  </script>

 

    <base-input v-model="username" :label="label" required placeholder="Enter your username"></base-input>
 

您的问题已经有小伙伴解答了,请点击【采纳】按钮,采纳帮您提供解决思路的答案,给回答的人一些鼓励哦~~

ps:开通问答VIP,享受5次/月 有问必答服务,了解详情↓↓↓

【电脑端】戳>>>  https://vip.csdn.net/askvip?utm_source=1146287632
【APP 】  戳>>>  https://mall.csdn.net/item/52471?utm_source=1146287632