在Vue中获取自定义属性方法:data-id的实例
获取自定义属性的方法:
第一步:首先在标签上绑定上@click="getDateId(item.id)",并将属性值传到绑定的事件里面
第二步:在标签上继续绑定:date-id="item.id"属性
第三步:在
补充知识:vue本地存储、获取自定义data-id、获取链接url参数、页面跳转返回、修改页面title
一、本地存储:
localStorage.setItem('uqid','REgaI2eAT9yDfpdc');//存储本地(传死参)
varuqid=localStorage.getItem('uqid');//获取存储本地值
或者
varorderSn=20; localStorage.setItem('orderSn',orderSn); varuqid=localStorage.getItem('orderSn');
二、获取自定义--------data-id
bindList(e){ varautoId=$(e.currentTarget).attr('data-id');//获取div-data },
三、获取链接---url参数
http://localhost:8080/#/lineitem?uqid=2019032817530157997(获取---uqid) bindList(){ varuqid=utils.getUrlKey('uqid'); alert(uqid); },
以上获取url参数需要引入js文件----utils.js
/*eslint-disable*/ exportdefault{ getUrlKey:function(name){ returndecodeURIComponent((newRegExp('[?|&]'+name+'='+'([^&;]+?)(&|#|;|$)').exec(location.href)||[,""])[1].replace(/\+/g,'%20'))||null } }
main.js全局引入下
importutilsfrom'./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文件中
importdoctorListfrom'@/components/doctorlist' exportdefaultnewRouter({ 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(); })
以上这篇在Vue中获取自定义属性方法:data-id的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。