在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。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程