VUE +Element 實(shí)現(xiàn)多個(gè)字段值拼接功能
效果截圖:
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, 遍歷后臺(tái)返回?cái)?shù)據(jù),常量str 的賦值表達(dá)式是:
str = res.data.notices[i].startDt + '~' + res.data.notices[i].endDt;
再向res.data.notices 數(shù)組對(duì)象中設(shè)置新的屬性值,并賦值:
res.data.notices[i].timeRang = str
補(bǔ)充:下面看下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)簽屬性綁定中的字符串拼接:寫(xiě)法有兩種::title="`字符串${xx}`" 或 :title="'字符串' + xx" 都可以。其中,{}里面可以寫(xiě)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 實(shí)現(xiàn)多個(gè)字段值拼接的文章就介紹到這了,更多相關(guān)vue element 字段值拼接內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue實(shí)現(xiàn)簡(jiǎn)單表格組件實(shí)例詳解
vue的核心思想就是組件,什么是組件呢?按照我的理解組件就是裝配頁(yè)面的零件,vue三大核心組件 路由 狀態(tài)管理,路由控制頁(yè)面的渲染,頁(yè)面由組件組成,數(shù)據(jù)有vuex進(jìn)行管理和改變。下面我會(huì)以一個(gè)簡(jiǎn)單的案例來(lái)說(shuō)2017-04-04Vue實(shí)現(xiàn)省市區(qū)級(jí)聯(lián)下拉選擇框
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)省市區(qū)級(jí)聯(lián)下拉選擇框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03淺談VUE防抖與節(jié)流的最佳解決方案(函數(shù)式組件)
這篇文章主要介紹了淺談VUE防抖與節(jié)流的最佳解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05vue-video-player 斷點(diǎn)續(xù)播的實(shí)現(xiàn)
這篇文章主要介紹了vue-video-player 斷點(diǎn)續(xù)播的實(shí)現(xiàn),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-02-02Vuejs第十一篇組件之slot內(nèi)容分發(fā)實(shí)例詳解
這篇文章主要介紹了Vuejs第十一篇之slot內(nèi)容分發(fā)組件詳解的相關(guān)資料2016-09-09