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: `是否確認(rèn)切換狀態(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)文章
vue3中使用router路由實現(xiàn)跳轉(zhuǎn)傳參的方法
這篇文章主要介紹了vue3中使用router路由實現(xiàn)跳轉(zhuǎn)傳參的方法,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-03-03
淺談vue中g(shù)et請求解決傳輸數(shù)據(jù)是數(shù)組格式的問題
這篇文章主要介紹了淺談vue中g(shù)et請求解決傳輸數(shù)據(jù)是數(shù)組格式的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08
vue父組件向子組件(props)傳遞數(shù)據(jù)的方法
這篇文章主要介紹了vue父組件向子組件(props)傳遞數(shù)據(jù)的方法,文中給大家補充介紹了vue父子組件間傳值(props)的實現(xiàn)代碼,需要的朋友可以參考下2018-01-01

