vue本地存储、获取自定义data-id、获取链接url参数、页面跳转返回、修改页面title

一、本地存储:
localStorage.setItem('uqid','REgaI2eAT9yDfpdc');    //存储本地(传死参)
var uqid = localStorage.getItem('uqid');            // 获取存储本地值
或者
var orderSn = 20;
localStorage.setItem('orderSn',orderSn);
var uqid = localStorage.getItem('orderSn');

二、获取自定义--------data-id
bindList(e){
	var autoId = $(e.currentTarget).attr('data-id');        //获取div -data   
},

三、获取链接---url参数
http://localhost:8080/#/lineitem?uqid =2019032817530157997           (获取---uqid )
bindList(){
	var uqid = utils.getUrlKey('uqid');
	alert(uqid );
},
以上获取url参数需要引入js文件----utils.js
/* eslint-disable */
export default{
    getUrlKey: function (name) {
        return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
    }
}

main.js全局引入下
import utils from './assets/js/utils.js'   //获取url参数
global.utils = utils;

四、页面跳转返回
 @click="bindReturn"
methods:{
	bindReturn(){
		this.$router.go(-1);                          //返回上一页,
	},			
	bindOrider(){   
		this.$router.push({path: '/doctorlist'});     //页面跳转
	},
}

router/index.js文件中
import doctorList from '@/components/doctorlist'
export default new Router({
	routes: [
		{ 
	      path:'/doctorlist',
	      name:'doctorList ',
	      component:doctorList ,
	      meta: {
	        title: '我是修改后的页面title'
	      }
	    },
	]
})

修改页面title--main.js 最后添加
// 修改页面title
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
})

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章