Get custom attribute method in Vue: an instance of data id


To get a custom property:

Step 1: Bind @ click= “getDateId (item. id)” on the tag and pass the attribute value to the bound event

Step 2: Continue binding on the tag: date-id = “item. id” attribute

Step 3: In the < script > The attribute methods is added with the event function getDateId (id) {} Get the value of id in the event function

<template>
<h2 class="left t-title" @click='getDataId(item.id)' :data-id="item.id"></h2>
</template>
<script>
  methods: {
    getDataId(id) {
      console.log(id);
    }
   },
</script>

Supplementary knowledge: vue local storage, get custom data-id, get link url parameters, page jump back, modify page title

1. Local storage:

localStorage. setItem (‘uqid’, ‘REgaI2eAT9yDfpdc’); //Store local (pass dead parameters)

var uqid = localStorage. getItem (‘uqid’); //Get stored local values

Or

var orderSn = 20;
localStorage.setItem('orderSn',orderSn);
var uqid = localStorage.getItem('orderSn');

2. Get customization-----data-id

bindList(e){
 var autoId = $(e.currentTarget).attr('data-id');    // Get div -data
},

3. Get the link—url parameter

http://localhost:8080/#/lineitem?uqid =2019032817530157997       (Gets ---uqid  )
bindList(){
 var uqid = utils.getUrlKey('uqid');
 alert(uqid );
},

To get the url parameters above, you need to import the js file—utils. js

/* eslint-disable */
export default{
  getUrlKey: function (name) {
    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
  }
}

Under the global introduction of main. js

ES75en ES76en ES77en ’./ES78en/ES79en/ES80en. ES81en’//Get ES82en parameters

global.utils = utils;

4. Page Jump Back

 @click="bindReturn"
methods:{
 bindReturn(){
 this.$router.go(-1);             // Back up 1 Page,
 },
 bindOrider(){
 this.$router.push({path: '/doctorlist'});   // Page jump
 },
}

In the router/index. js file

import doctorList from '@/components/doctorlist'
export default new Router({
 routes: [
 {
    path:'/doctorlist',
    name:'doctorList ',
    component:doctorList ,
    meta: {
     title: ' I am the modified page title'
    }
   },
 ]
})

Modify page title—main. js last added

//  Modify Page title
router.beforeEach((to, from, next) => {
 /*  Route Change Modification Page title */
 if (to.meta.title) {
  document.title = to.meta.title;
 }
 next();
})