vue中的循環(huán)對象屬性和屬性值用法
v-for除了可以循環(huán)數(shù)組,還可以循環(huán)對象。
例子:
<template><div> <div v-for='(item,i) in obj'>{{i}}--{{item}}</div></div></template><script>export default { name: 'HelloWorld', data () { return { obj:{ age:1, name:'zs', sex:'男' } }; }}</script><style lang='css' scoped></style>
結(jié)果:
補充知識:Vue控制路由滾動行為
跳轉(zhuǎn)路由時,要求跳轉(zhuǎn)到指定路由的某個地方,可以使用scrollBehavior方法控制。
用法:
scrollBehavior(to,from,savedPosition){ }
scrollBehavior方法可以返回x,y 坐標點,也可以返回指定的選擇器
例子:
import Vue from ’vue’import Router from ’vue-router’ import Home from ’../../view/Home.vue’ import Test from ’../../view/Test.vue’ import News from ’../../view/News.vue’Vue.use(Router)export default new Router({ routes: [ { name:'Home', component:Home, path:'/' }, { name:'Test', component:Test, path:'/test' }, { name:'News', component:News, path:'/news' }, { path:'*', redirect:'/' } ], mode:'history', //跳轉(zhuǎn)到指定路由的指定坐標 scrollBehavior(to,from,savedBehavior){ if(to.path==='/test'){ return { x:0, y:100 } }; // 跳轉(zhuǎn)到指定的選擇器 if(to.path==='/news'){ return { selector:'.here' } } }})
以上這篇vue中的循環(huán)對象屬性和屬性值用法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Gitlab CI-CD自動化部署SpringBoot項目的方法步驟2. ASP基礎知識VBScript基本元素講解3. ajax請求添加自定義header參數(shù)代碼4. Kotlin + Flow 實現(xiàn)Android 應用初始化任務啟動庫5. 基于javascript處理二進制圖片流過程詳解6. 使用Python和百度語音識別生成視頻字幕的實現(xiàn)7. ASP中解決“對象關(guān)閉時,不允許操作。”的詭異問題……8. 教你如何寫出可維護的JS代碼9. 使用python 計算百分位數(shù)實現(xiàn)數(shù)據(jù)分箱代碼10. ASP刪除img標簽的style屬性只保留src的正則函數(shù)
