Vue学习 - :xxx=“变量“

本文通过一个具体的Vue下拉框例子,探讨了在`:label`前添加冒号导致的问题。当在`el-option`的`label`属性前加上冒号时,Vue将其视为一个变量,但在实际业务逻辑中未定义,导致下拉框显示value值而非预期的label文字。分析指出,冒号在Vue中代表双向绑定,意味着组件属性的值会根据业务逻辑变化。总结强调了Vue中属性修饰符的重要性和正确使用方式。

一、:xxx="变量"问题描述

以下拉框为例解释:

<el-col :span="9">
   <el-form-item label="状态:">
      <el-select v-model="formInline.osiStatus" placeholder="请选择">
          <el-option value="1" label="正常">正常</el-option>
          <el-option value="2" label="异常">异常</el-option>
          <el-option value="3" label="隐患">隐患</el-option>
     </el-select>
   </el-form-item>
</el-col>

选择【下拉框选项时】显示的是 正常、异常、隐患
在这里插入图片描述

<el-col :span="9">
   <el-form-item label="状态:">
      <el-select v-model="formInline.osiStatus" placeholder="请选择">
          <el-option value="1" :label="正常">正常</el-option>
          <el-option value="2" :label="异常">异常</el-option>
          <el-option value="3" :label="隐患">隐患</el-option>
     </el-select>
   </el-form-item>
</el-col>

选择【下拉框选项时】显示的是 1、2、3
在这里插入图片描述

二、分析

当我在label前添加:时,那么就意味着‘正常’、‘异常’、‘隐患’为三个变量,但我下文的业务逻辑中并未对这三个变量进行赋值。所以切换value时找不到对应的label,也就默认显示value的值。

三、总结

组件属性前添加:代表双向绑定-定义的值可以根据业务逻辑更改而更改(可以理解为是这个组件属性定义了一个变量,业务逻辑中对这个组件属性定义的变量值进行了修改,那么组件值也会发生修改)

341 和 342 行部分: <a-col :span="12"> <a-form-model-item prop="searchData.StepForms[index].eqpMode" label="Equipment:" :labelCol="{ span: 6 }" :wrapperCol="{ span: 12, offset: 2 }" :required=&#39;required&#39;> <a-select placeholder="请选择" v-model="step.eqpMode" style="width: 100%" > <a-select-option v-for="item in StepEqpModeList" :key="item">{{ item }}</a-select-option> </a-select> </a-form-model-item> <a-form-model-item prop="searchData.StepForms[index].eqpModeName" "> <a-input v-model="step.eqpModeName" placeholder="Enter Step No" " /> <div style="color: red; margin-top: 4px;"> EqpGroup区分大小写,输入的EqpID最大长度7位!!! </div> </a-form-model-item> </a-col>438-460行:<!-- Wafer 选择弹窗 --> <a-modal v-model:visible="isWaferModalVisible" title="选择 WaferID" @ok="handleWaferOk" okText="确定" cancelText="取消"> <a-checkbox-group v-model:value="selectedWaferIDs"> <a-row> <a-col v-for="id in waferList" :key="id" :span="6"> <a-checkbox :value="id">{{ id }}</a-checkbox> </a-col> </a-row> </a-checkbox-group> </a-modal> <!-- Wafer 选择弹窗 --> <a-modal v-model:visible="isMeasWaferModalVisible" title="选择 WaferID" @ok="handleMeasWaferOk" okText="确定" cancelText="取消"> <a-checkbox-group v-model:value="selectedMeasWaferIDs"> <a-row> <a-col v-for="id in waferList" :key="id" :span="6"> <a-checkbox :value="id">{{ id }}</a-checkbox> </a-col> </a-row> </a-checkbox-group> </a-modal> 851行: this.searchData.StepForms.push({ stepNo: "", description: "", operator: "", date: null, isReadOnlyStepNo: false, stepSerialNo: index + 1, // 动态赋值 waferId: [], waferIdQty: 0, slotId: [], slotIdQty: 0 }); },
11-02
为什么后端传回数据后,并不能在前端显示: <a-card :title="`Run Card Step${index + 1}`" style="margin-top: 10px"> <a-row> <a-col :span="12"> <a-form-model-item :prop="&#39;StepForms.&#39; + index + &#39;.StepForm.fabName&#39;" label="Fab Area:" :labelCol="{ span: 6 }" :wrapperCol="{ span: 12, offset: 2 }" :required=&#39;required&#39;> <a-select placeholder="请选择" v-model="step.fabName" style="width: 100%" :disabled="step.isSubmitted"> <a-select-option v-for="item in StepFabAreaList" :key="item">{{ item }}</a-select-option> </a-select> </a-form-model-item> </a-col> <a-col :span="12"> <a-form-model-item prop="&#39;StepForms.&#39; + index + &#39;.StepForm.area&#39;" label="Area:" :labelCol="{ span: 6 }" :wrapperCol="{ span: 12, offset: 2 }" :required=&#39;required&#39;> <a-select placeholder="请选择" v-model="step.area" style="width: 100%" :disabled="step.isSubmitted"> <a-select-option v-for="item in StepAreaList" :key="item">{{ item }}</a-select-option> </a-select> </a-form-model-item> </a-col> </a-row> <a-row> <a-col :span="16"> <a-form-model-item prop="&#39;StepForms.&#39; + index + &#39;.StepForm.stepNo&#39;" label="Reference Step No" :labelCol="{ span: 6 }" :wrapperCol="{ span: 12 }" :required=&#39;required&#39;> <div style="display: flex; align-items: center; gap: 8px; white-space: nowrap;"> <a-checkbox v-model="step.isReadOnlyStepNo">NA</a-checkbox> <a-input v-model="step.stepNo" placeholder="Enter Step No" :disabled="step.isReadOnlyStepNo || step.isSubmitted" style="flex: 1; height: 32px;" /> {{index}}<a-button @click="getStepLotInfo(index)" style="height: 32px;">Go</a-button> <a-button @click="getfuturestepinfo(index)" style="height: 32px;">ViewFutureStep</a-button> </div> </a-form-model-item> </a-col> </a-row> <a-row> <a-col :span="12"> <a-form-model-item prop="&#39;StepForms.&#39; + index + &#39;.StepForm.eqpMode&#39;" label="Equipment:" :labelCol="{ span: 6 }" :wrapperCol="{ span: 6, offset: 2 }" :required=&#39;required&#39;> <a-select placeholder="请选择" v-model="step.eqpMode" style="width: 100%" :disabled="step.isSubmitted"> <a-select-option v-for="item in StepEqpModeList" :key="item">{{ item }}</a-select-option> </a-select> </a-form-model-item> </a-col> <a-col :span="12"> <a-form-model-item prop="&#39;StepForms.&#39; + index + &#39;.StepForm.eqpModeName&#39;" label="" :labelCol="{ span: 6 }" :wrapperCol="{ span: 20, offset: 2 }" :required=&#39;required&#39;> <div style="display: flex; align-items: center; gap: 8px; Height: 40px;"> <a-input v-model="step.eqpModeName" :disabled="step.isSubmitted" /> <div style="color: red; white-space: nowrap;"> EqpGroup区分大小写,输入的EqpID最大长度7位!!! </div> </div> </a-form-model-item> </a-col> </a-row> <a-row> <a-col :span="12"> <a-form-model-item prop="&#39;StepForms.&#39; + index + &#39;.StepForm.recipe&#39;" label="Recipe:" :labelCol="{ span: 6 }" :wrapperCol="{ span: 12 , offset: 2}" :required=&#39;required&#39;> <div style="display: flex; align-items: center; gap: 8px; Height: 40px;"> <a-input v-model="step.recipe" :disabled="step.isSubmitted" /> <div style="color: red; white-space: nowrap;"> 区分大小写!!! </div> </div> </a-form-model-item> </a-col> </a-row> <a-row> <!-- WaferID 显示和弹窗按钮 --> <a-col :span="18"> <a-form-model-item prop="&#39;StepForms.&#39; + index + &#39;.StepForm.waferId&#39;" label="WaferID" :labelCol="{ span: 3 }" :wrapperCol="{ span: 15 }"> <a-input :value="step.waferId" placeholder="请选择 WaferID" @click="() => openWaferModal(index)" readonly style="cursor: pointer" :disabled="step.isSubmitted" /> </a-form-model-item> </a-col> <!-- QTY 数量显示 --> <a-col :span="6"> <a-form-model-item prop="&#39;StepForms.&#39; + index + &#39;.StepForm.waferIdQty&#39;" label="QTY" :labelCol="{ span: 3 }" :wrapperCol="{ span: 3 }"> <a-input :value="step.waferIdQty.toString()" readonly :disabled="step.isSubmitted" /> </a-form-model-item> </a-col> </a-row> <a-row> <!-- MeasWaferID 显示和弹窗按钮 --> <a-col :span="18"> <a-form-model-item prop="&#39;StepForms.&#39; + index + &#39;.StepForm.slotId&#39;" label="MeasSlotId" :labelCol="{ span: 3 }" :wrapperCol="{ span: 15 }"> <a-input :value="step.slotId" placeholder="请选择量测 WaferID" @click="() => openMeasWaferModal(index)" readonly style="cursor: pointer" :disabled="step.isSubmitted" /> </a-form-model-item> </a-col> <!-- MeasWaferIDQTY 数量显示 --> <a-col :span="6"> <a-form-model-item prop="&#39;StepForms.&#39; + index + &#39;.StepForm.slotIdQty&#39;" label="QTY" :labelCol="{ span: 3 }" :wrapperCol="{ span: 3 }"> <a-input :value="step.slotIdQty.toString()" readonly :disabled="step.isSubmitted" /> </a-form-model-item> </a-col> </a-row> <a-row> <a-col :span="12"> <a-form-model-item prop="&#39;StepForms.&#39; + index + &#39;.StepForm.contaminationFlag&#39;" label="ContaminationFlag:" :labelCol="{ span: 6 }" :wrapperCol="{ span: 12, offset: 2 }" :required=&#39;required&#39;> <a-select placeholder="请选择" v-model="step.contaminationFlag" style="width: 100%" :disabled="step.isSubmitted"> <a-select-option v-for="item in contaminationFlagList" :key="item">{{ item }}</a-select-option> </a-select> </a-form-model-item> </a-col> <a-col :span="12"> <a-form-model-item prop="&#39;StepForms.&#39; + index + &#39;.StepForm.remark&#39;" label="Remark:" :labelCol="{ span: 6 }" :wrapperCol="{ span: 16 }"> <a-textarea v-model="step.remark" placeholder="100字内..." :rows="3" :disabled="step.isSubmitted" /> <!-- 始终显示的红字提示 --> <div style="color: red; margin-top: 4px;"> 如果输入中文,Runcard只能Manual Run!!! </div> </a-form-model-item> </a-col> <a-col :span="12"> <a-form-model-item prop="&#39;StepForms.&#39; + index + &#39;.StepForm.ecdPlanName&#39;" label="EDC Plan Name:" :labelCol="{ span: 6 }" :wrapperCol="{ span: 16 }"> <a-input v-model="step.ecdPlanName" placeholder="Enter EDC PlanName" :disabled="step.isSubmitted" /> <a-button @click="submitstepinfo()">Go</a-button> </a-form-model-item> </a-col> <a-col :span="12"> <a-form-model-item prop="&#39;StepForms.&#39; + index + &#39;.StepForm.spec&#39;" label="量测规格SPEC:" :labelCol="{ span: 6 }" :wrapperCol="{ span: 16 }"> <a-input v-model="step.spec" :disabled="disabled" /> </a-form-model-item> </a-col> </a-row> <!-- Qtime 展示区域 --> <div v-if="StepForms[index].stepQtimeEndList && StepForms[index].stepQtimeEndList.length > 0"> <a-card style="margin-top: 20px" title="Step Qtime Information"> <a-table :dataSource="StepForms[index].stepQtimeEndList" :columns="StepQtimeStrEndColumns" :pagination="false" :rowKey="record => record.id || Math.random()" bordered > <!-- 注意这里使用 { record, index } 解构 --> <template #handleMode="record, index"> <a-select :value="index.action" @change="(value) => onHandleModeChange(index, value)" style="width: 120px" > <a-select-option value="NULL">NULL</a-select-option> <a-select-option value="Ignore">Mapping</a-select-option> </a-select> </template> </a-table> </a-card> </div> <!-- Qtime 展示区域 --> <div v-if="StepForms[index].stepQtimeList && StepForms[index].stepQtimeList.length > 0"> <a-card style="margin-top: 20px" title="Step Qtime Information"> <a-table :dataSource="StepForms[index].stepQtimeList" :columns="StepQtimeStrColumns" :pagination="false" :rowKey="record => record.id || Math.random()" bordered > </a-table> </a-card> </div> <a-row> <a-col :span="24"> <a-form-model-item label="" :labelCol="{ span: 6 }" :wrapperCol="{ span: 12, offset: 10 }"> <a-button @click="updatestepinfo(index)">Update</a-button> <a-button @click="deletestepinfo(index)">Delete</a-button> <a-button @click="submitstepinfo(index)">Submit</a-button> </a-form-model-item> </a-col> </a-row> </a-card>
11-16
<template> <div class="container"> <div class="content"> <el-tabs v-model="activeName" stretch class="asset-efficity-tabs"> <el-tab-pane :lazy="false" :label="t(&#39;盘点差异&#39;) + &#39;(&#39; + handelNumber(data.top.ciagabnormalsitetotalcount) + &#39;)&#39;" name="inventoryDiscrepancy" > <CountingDiscrepancy v-if="activeName === &#39;inventoryDiscrepancy&#39;" :data="props.data" :activeName="activeName" :productRole="props.productRole" :title="title" /> </el-tab-pane> <el-tab-pane :lazy="false" :label="t(&#39;无保全协议&#39;) + &#39;(&#39; + handelNumber(data.top.noagreementsitecount) + &#39;)&#39;" name="noSecurityAgreement" > <OtherType v-if="activeName === &#39;noSecurityAgreement&#39;" :data="props.data" :activeName="activeName" :title="title" /> </el-tab-pane> <el-tab-pane :lazy="false" :label="t(&#39;未覆盖解决方案&#39;) + &#39;(&#39; + handelNumber(data.top.nosolutionsitecount) + &#39;)&#39;" name="solutionNotCovered" > <OtherType v-if="activeName === &#39;solutionNotCovered&#39;" :data="props.data" :activeName="activeName" :title="title" /> </el-tab-pane> <el-tab-pane :lazy="false" :label="t(&#39;解决方案部署中&#39;) + &#39;(&#39; + handelNumber(data.top.solutiondeploysitecount) + &#39;)&#39;" name="solutionDeployment" > <OtherType v-if="activeName === &#39;solutionDeployment&#39;" :data="props.data" :activeName="activeName" :title="title" /> </el-tab-pane> </el-tabs> </div> </div> </template> <script lang="ts" setup> import { ref } from &#39;vue&#39;; import { useI18n } from &#39;vue-i18n&#39;; import CountingDiscrepancy from &#39;./components/CountingDiscrepancy.vue&#39;; import OtherType from &#39;@/views/DCPhysicalArchitecture/GlobalLayout/components/AsideLayout/components/AssetSafetyAside/components/OtherType.vue&#39;; const { t } = useI18n(); const activeName = ref<string>(&#39;inventoryDiscrepancy&#39;); const props = defineProps({ title: String, data: Object, productRole: Object, }); const handelNumber = (num, fixed?: number) => { if (num || num === 0) { return fixed ? `${Number(num).toFixed(fixed)}%` : num; } else { return &#39;--&#39;; } }; </script> <style lang="less" scoped> .container { width: 100%; padding: 0 20px 100px 20px; overflow: hidden; background-color: #fff; border-radius: 10px; :deep(.asset-efficity-tabs) { .el-tabs__item { padding: 0px 4px; } } } .dark { .container { background: #282b33; border: 1px solid rgba(223, 225, 230, 0.1); color: #dfe1e6; :deep(.asset-efficity-tabs) { .el-tabs__item.is-active { color: #715afb; } .el-tabs__item { color: #dfe1e6; &:hover { color: #715afb; } } .el-tabs__active-bar { background: #715afb; } .el-tabs__header { border-bottom-color: #53555c; } .el-tabs__nav-wrap::after { background: #53555c; } } } } </style> 这是AssetTabCar.vue
09-21
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值