vue项目笔记
将后台传过来的 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 } } },
https://www.jianshu.com/p/72021f3a9f05 vue项目笔记
此随笔或为自己所写、或为转载于网络。仅用于个人收集及备忘。