vue.js template v-if v-else 判断 难道是不能在template里做判断?

79 阅读1分钟

错误的:为何订单已付款 未付款 数量 都可以编辑?难道是不能在template里做判断?

<el-table-column label="数量" width="80">
    <!--订单已付款-->
    <template v-if="model.paymentStatus===1" slot-scope="scope">
        <span class="nowrap">{{scope.row.quantity}}</span>
    </template>
    <!--订单未付款-->
    <template v-else slot-scope="scope">
        <el-input v-model="scope.row.quantity" @blur="handleQuantityChange(scope.row)" type="number"></el-input>
    </template>
</el-table-column>

正确的:只有一个template 思考:难道是不能在template里做判断?只能有一个template?

<el-table-column label="数量" width="100">
    <template slot-scope="scope">
        <!--订单已付款已付款订单不能修改数量-->
        <div v-if="model.paymentStatus=='1'">
            <span class="nowrap">{{scope.row.quantity}}</span>
        </div>
        <!--订单未付款-->
        <div v-else>
            <el-input v-model="scope.row.quantity" @blur="handleQuantityChange(scope.row)" type="number"></el-input>
        </div>
    </template>
</el-table-column>