The error message suggests that the component template in the file 'code.vue' does not contain exactly one root element. It seems that there are multiple root elements in the template, which is not allowed.

To fix this issue, you need to wrap all the elements inside a single parent element. For example, you can wrap all the elements inside a <div> tag. Here's an example:

<template>
  <div>
    <input class='price' type='number' placeholder='输入金额' v-model='info.money'/>
  
    <view class='line line1'>
      <view class='line1-title'>使用ZJT</view>
      <switch :checked='info.useQt!=0' color='#0E7519' style='transform:scale(0.7)' @change='onChangeQtCoupon'/>
    </view>
  
    <!-- Rest of the elements -->
  
    <view class='bottom'>
      <span>待支付:<label class='price-red'>¥{{getToPayPrice()}}</label></span>
      <span>抵扣:{{info.couponMoney}}</span>
      <button class='btn-pay' @click='onPay'>去支付</button>
    </view>
  </div>
</template>

Make sure to wrap all the elements inside a single parent element and the error should be resolved.

解决 Vue.js 模板编译错误:Component template should contain exactly one root element

原文地址: https://www.cveoy.top/t/topic/cg03 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录