将背景傳過來的 json 數組裡面的 name 換成 text
this.columns = JSON.parse(JSON.stringify(res.data.data.data).replace(/r_name/g,'text'))
// res.data.data.data 是需要替換的對象數組
// r_name 是替換前的
// text 是替換後
相容低版本的IE
<meta name=’viewport’ content=”width=device-width, initial-scale=1. maximum-scale=1,user-scalable=no”>
給每個頁面加title
router.beforeEach((to,from,next)=>{
// 為頁面添加标題
if (to.meta.title) {
document.title = to.meta.title
}
next()
})
router.js 中給每個路由下添加一個meta 對象,内部加入 title。
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
function loadView(view) {
return () => import(/* webpackChunkName: "view-[request]" */ `@/components/${view}.vue`)
}
export default new Router({
mode: 'history',
base: 'view',
routes: [
{
path: '/',
name: 'HelloWorld',
component: loadView('HelloWorld'),
meta:{
index:2,
auth:true,
title:'使用者中心'
}
},
{
path: '/addCarInfo',
name: 'AddCarInfo',
component: loadView('AddCarInfo'),
meta:{
index:3,
auth:true,
title:'綁定車輛資訊'
}
},
]
})
對象數組查重方法
unique(arr){
let unique = {};
arr.forEach(function(item){
unique[JSON.stringify(item)]=item;//鍵名不會重複
})
arr = Object.keys(unique).map(function(u){
//Object.keys()傳回對象的所有鍵值組成的數組,map方法是一個周遊方法,
//傳回周遊結果組成的數組.将unique對象的鍵名還原成對象數組
return JSON.parse(u);
})
return arr;
}
every校驗數組中元素
checkAllSuccess() {
return Object.keys(this.listObj).every(item => this.listObj[item].hasSuccess)
},
json變量毛篩選集合:
listObj: {},
const arr = Object.keys(this.listObj).map(v => this.listObj[v])
handleSuccess(response, file) {
const uid = file.uid
const objKeyArr = Object.keys(this.listObj)
for (let i = 0, len = objKeyArr.length; i < len; i++) {
if (this.listObj[objKeyArr[i]].uid === uid) {
this.listObj[objKeyArr[i]].url = response.files.file
this.listObj[objKeyArr[i]].hasSuccess = true
return
}
}
},
此随筆或為自己所寫、或為轉載于網絡。僅用于個人收集及備忘。