VUE +Element 實現多個字段值拼接功能
效果截圖:
VUE 核心功能代碼片段:
//獲取公共通知列表 getUsers() { let para = { page: this.page, title: this.filters.title }; this.listLoading = true; //NProgress.start(); getNoticeListPage(para).then((res) => { this.total = res.data.total; let str = '' for(let i =0; i < res.data.notices.length; i++) { str = res.data.notices[i].startDt + '~' + res.data.notices[i].endDt; res.data.notices[i].timeRang = str } this.notices = res.data.notices; this.listLoading = false; //NProgress.done(); }); },
總結:定義常量str, 遍歷后臺返回數據,常量str 的賦值表達式是:
str = res.data.notices[i].startDt + '~' + res.data.notices[i].endDt;
再向res.data.notices 數組對象中設置新的屬性值,并賦值:
res.data.notices[i].timeRang = str
補充:下面看下vue各種字符串拼接方法
1、文件綁定{undefined{}}中的字符串拼接:直接在{undefined{}}內拼接:
? <template v-if="userList"> ? ? ? ? ? ? ? <div v-for="(item,index) in userList" :key="index"> ? ? ? ? ? ? ? ? {{item.userName+'('+item.userAccount+')'}} ? ? ? ? ? ? ? </div> ?</template> <el-option ? ? ? ? ? ? ? ? v-for="item in projectList" ? ? ? ? ? ? ? ? :key="item.pNo" ? ? ? ? ? ? ? ? :label='`${item.name}-${item.managerName}(${item.managerAccount})`' ? ? ? ? ? ? ? ? :value="item.pNo" ? ? ? ? ? ? ? > ? ? ? ? ? ? ? </el-option>
2、vue標簽屬性綁定中的字符串拼接:寫法有兩種::title="`字符串${xx}`" 或 :title="'字符串' + xx" 都可以。其中,{}里面可以寫js方法。如:
?<el-option ? ? ? ? ? ? ? ? ? v-for="item in tableData" ? ? ? ? ? ? ? ? ?:key="item.account" ? ? ? ? ? ? ? ? ?:label= '`${item.name}${item.account}`' ? ? ? ? ? ? ? ? ?:value="item.account" ? ? ? ? ? ? ? ? ?:height = "schoolHeight"> ? ? ? ? ? ? ? ?</el-option> ?<el-submenu v-show="item.childList.length > 0" :index="item.id" ?:class='`menu${item.id}`'> ?<span :class="{ red: originData[`${item.value}ChangeFlag`] }">{{ item.text }}</span>
3、js中的字符串拼接:
this.personList.forEach(item => { ? ? ? ? ? item.label = `${item.userName}(${item.account})`; ? ? ? ? }); this.$bus.$emit(`${this.activeName}-reload`, this.searchData); switchStatus(row) { ? ? ? this.$Modal.confirm({ ? ? ? ? title: '提示', ? ? ? ? content: `是否確認切換狀態(tài)為${row.isDelete === 1 ? '否' : '是'}?`, ? ? ? ? onOk: () => { ? ? ? ? ? row.isDelete = row.isDelete === 0 ? 1 : 0; ? ? ? ? } ? ? ? }); ? ? },
到此這篇關于VUE +Element 實現多個字段值拼接的文章就介紹到這了,更多相關vue element 字段值拼接內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!