VUE +Element 實現(xiàn)多個字段值拼接功能
效果截圖:

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();
});
},總結(jié):定義常量str, 遍歷后臺返回數(shù)據(jù),常量str 的賦值表達式是:
str = res.data.notices[i].startDt + '~' + res.data.notices[i].endDt;
再向res.data.notices 數(shù)組對象中設(shè)置新的屬性值,并賦值:
res.data.notices[i].timeRang = str
補充:下面看下vue各種字符串拼接方法
1、文件綁定{undefined{}}中的字符串拼接:直接在{undefined{}}內(nèi)拼接:
? <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標(biāo)簽屬性綁定中的字符串拼接:寫法有兩種::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;
? ? ? ? }
? ? ? });
? ? },到此這篇關(guān)于VUE +Element 實現(xiàn)多個字段值拼接的文章就介紹到這了,更多相關(guān)vue element 字段值拼接內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue實現(xiàn)省市區(qū)級聯(lián)下拉選擇框
這篇文章主要為大家詳細介紹了Vue實現(xiàn)省市區(qū)級聯(lián)下拉選擇框,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-03-03
淺談VUE防抖與節(jié)流的最佳解決方案(函數(shù)式組件)
這篇文章主要介紹了淺談VUE防抖與節(jié)流的最佳解決方案,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
vue-video-player 斷點續(xù)播的實現(xiàn)
這篇文章主要介紹了vue-video-player 斷點續(xù)播的實現(xiàn),本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-02-02
Vuejs第十一篇組件之slot內(nèi)容分發(fā)實例詳解
這篇文章主要介紹了Vuejs第十一篇之slot內(nèi)容分發(fā)組件詳解的相關(guān)資料2016-09-09

