在Vue中获取自定义属性方法:data-id的实例
网络编程 2021-07-04 14:06www.168986.cn编程入门
这篇文章主要介绍了在Vue中获取自定义属性方法:data-id的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随长沙网络推广过来看看吧
获取自定义属性的方法
第一步在标签上绑定上@click="getDateId(item.id)",并将属性值传到绑定的事件里面
第二步在标签上继续绑定date-id = "item.id"属性
第三步在<script>里面的属性methods里面添写上事件函数 getDateId(id){} 在事件函数里面获取id的值即可
<template> <h2 class="left t-title" @click='getDataId(item.id)' :data-id="item.id"></h2> </template> <script> methods: { getDataId(id) { console.log(id); } }, </script>
补充知识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 '@/ponents/doctorlist' export default new Router({ routes: [ { path:'/doctorlist', name:'doctorList ', ponent: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的实例就是长沙网络推广分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持狼蚁SEO。
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指