VUE表達式{{}}中如何拼接字符
VUE表達式{{}}中拼接字符
在表達式中我們一直都只綁定簡單的鍵值。
但實際上,對于所有的數(shù)據(jù)綁定,Vue.js 都提供了完全的 JavaScript 表達式支持。
例如:
{{ number + 1 }}?? ?{{ ok ? 'YES' : 'NO' }}{{ message.split('').reverse().join('') }}但是最近我有一個需求,就是在表達式中進行一個拼接。
? ? ? ? <div class="appdouble_data">
? ? ? ? ? <div class="BonusPoolDetails_data"
? ? ? ? ? v-for = 'item,index in list'
? ? ? ? ? >
? ? ? ? ? ? <div class="BonusPoolDetails_data_tit">
? ? ? ? ? ? ? {{item.start_at}}至{{item.end_at}}
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class="data_flex">
? ? ? ? ? ? ? <div class="data_flex_tit flex align-cen">
? ? ? ? ? ? ? ? <div>推薦人數(shù)</div>
? ? ? ? ? ? ? ? <div>獎金池</div>
? ? ? ? ? ? ? ? <div>累計獎金</div>
? ? ? ? ? ? ? ? <div>獲得分紅</div>
? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? <div class="data_flex_list flex align-cen"
? ? ? ? ? ? ? v-for = 'props,key in item.has_details'
? ? ? ? ? ? ? >
? ? ? ? ? ? ? ? <div>{{props.invite_number}}</div>
? ? ? ? ? ? ? ? <div>{{props.pool_index}}</div>
? ? ? ? ? ? ? ? <div>{{item[String(props.pool_index) + '_pool']}}</div>
? ? ? ? ? ? ? ? <div>{{props.money}}</div>
? ? ? ? ? ? ? </div>
? ? ? ? ? ? </div>
? ? ? ? ? </div>
? ? ? ? </div>大家著重看這段代碼
{{item[String(props.pool_index) + '_pool']}}這個是利用第二個循環(huán)里的一個數(shù)據(jù)props.pool_index來拼接成第一個循環(huán)里的相對應一個數(shù)據(jù)(item.4_pool)
VUE字符串拼接路由path路徑
功能:產(chǎn)品列表頁面進入產(chǎn)品詳情頁面,產(chǎn)品詳情中四個模塊之間切換
products.vue進入detail.vue頁面,
detail.vue中配置子路由
第一步
products.vue
<ul class="pro"> ?? ??? ?<router-link to="/detail/pro1" tag="li">產(chǎn)品1</router-link> ?? ??? ?<router-link to="/detail/pro2" tag="li">產(chǎn)品2</router-link> ?? ??? ?<router-link to="/detail/pro3" tag="li">產(chǎn)品3</router-link> ?? ??? ?<router-link to="/detail/pro4" tag="li">產(chǎn)品4</router-link> </ul>
第二步
router/index.js 路由配置
? ? ?{
? ? ? path: '/detail/:id',
? ? ? component: Detail,
?? ??? ??? ?children:[
?? ??? ??? ??? ? ? { path: 'c1', component: C1},
?? ??? ??? ??? ? ? { path: 'c2', component: C2},
?? ??? ??? ??? ? ? { path: 'c3', component: C3},
?? ??? ??? ??? ? ? { path: 'c4', component: C4}
?? ??? ??? ?]
? ? }第三步
detail.vue中接收產(chǎn)品列表中傳遞過來的參數(shù),并實現(xiàn)子路由的切換
<ul class="detail-left">
<li><h3>產(chǎn)品{{this.$route.params.id}}</h3></li>
?? ?<router-link tag="li" :to='{path:"/detail/"+this.$route.params.id+"/c1"}'>數(shù)據(jù)統(tǒng)計</router-link>
?? ?<router-link tag="li" :to='{path:"/detail/"+this.$route.params.id+"/c2"}'>數(shù)據(jù)預測</router-link>
?? ?<router-link tag="li" :to='{path:"/detail/"+this.$route.params.id+"/c3"}'>數(shù)據(jù)分析</router-link>
?? ?<router-link tag="li" :to='{path:"/detail/"+this.$route.params.id+"/c4"}'>廣告發(fā)布</router-link>
</ul>注意:
1.接參數(shù)的方式是this.$route.params.id中的id和路由中配置的 path: '/detail/:id’的id對應,這個id相當于一個變量
2.路由路徑中字符串拼接放方式可以這樣寫
:to='{path:"/detail/"+this.$route.params.id+"/c1"}'完整index.js配置如下
import Vue from 'vue'
import Router from 'vue-router'
import Detail from "../detail/detail"
import Home from "../home/home"
import C1 from "../detail/child1"
import C2 from "../detail/child2"
import C3 from "../detail/child3"
import C4 from "../detail/child4"
import HotDetail from "../home/hot-detail"
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
component: Home
},
{
path:"/hotdetail",
component:HotDetail
},
{
path: '/detail/:id',
component: Detail,
children:[
{
path: 'c1',
component: C1
},
{
path: 'c2',
component: C2
},
{
path: 'c3',
component: C3
},
{
path: 'c4',
component: C4
},
]
}
]
})總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue引入路徑正確但一直報錯問題:Already included file name&n
這篇文章主要介紹了Vue引入路徑正確但一直報錯:Already included file name ‘××ב differs from file name ‘××ב only in casing.具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12
vue3+Element Plus實現(xiàn)自定義穿梭框的詳細代碼
找到一個好用的vue樹形穿梭框組件都很難,又不想僅僅因為一個穿梭框在element-ui之外其他重量級插件,本文給大家分享vue3+Element Plus實現(xiàn)自定義穿梭框的示例代碼,感興趣的朋友一起看看吧2024-01-01
Vue-cli Eslint在vscode里代碼自動格式化的方法
本篇文章主要介紹了Vue-cli Eslint在vscode里代碼自動格式化的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-02-02
npm run serve運行vue項目時報錯:Error: error:0308010C
這篇文章主要介紹了npm run serve運行vue項目時,出現(xiàn)報錯:Error: error:0308010C:digital envelope routines::unsupported的解決方法,文中有詳細的解決方法,需要的朋友可以參考下2024-04-04
element-ui重置resetFields()不生效的解決
本文主要介紹了element-ui重置resetFields()不生效的解決,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-12-12

