【问题标题】:Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead [duplicate]组件模板应该只包含一个根元素。如果您在多个元素上使用 v-if,请改用 v-else-if 链接它们[重复]
【发布时间】:2018-04-23 18:36:18
【问题描述】:

请帮助我的 Form.vue 代码

<template>
<div v-if="alert.message" :class="['alert alert-' + alert.type]">
  <p>{{ alert.message }}</p>
</div>
<div class="col-md-4">
   <div :class="['form-group', 'label-floating',{ 'has-error' : errors.city}]">
       <label class="control-label">Kota</label>
       <select @change="city" v-model="state.city" class="form-control" required>
         <option v-for="city in cities" :value="city.kota_id">{{city.kota_nama}}</option>
       </select>
       <span v-if="errors.city" class="label label-danger">
       {{ errors.city[0]}}
       </span>
   </div>
</div>
<div class="col-md-4">
   <div :class="['form-group', 'label-floating',{ 'has-error' : errors.profile}]">
       <label  class="control-label">Tahun</label>
       <select @change="profile" v-model="state.profle" class="form-control" required>
         <option v-for="profile in profiles" :value="profile.profile_id">{{profile.profile_tahun}}</option>
       </select>
       <span v-if="errors.profile" class="label label-danger">
       {{ errors.profile[0]}}
       </span>
   </div>
</div>

我很困惑,我的错误...我尝试更改 v-show 并且仍然得到类似的错误

Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead. 

【问题讨论】:

    标签: laravel vue.js


    【解决方案1】:

    这意味着你放在&lt;template&gt;&lt;/template&gt; 中的任何东西都应该放在另一个元素中。

    因此,请始终在这些标签中创建一个 div,例如:

    <template>
      <div>
          <!-- put all your code here -->
      </div>
    </template>
    

    【讨论】:

      猜你喜欢
      • 2018-05-29
      • 2017-09-20
      • 2019-03-22
      • 2017-12-13
      • 1970-01-01
      • 2019-05-30
      • 1970-01-01
      • 2020-08-08
      • 2017-10-26
      相关资源
      最近更新 更多