国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

在Vue中獲取自定義屬性方法:data-id的實(shí)例

瀏覽:40日期:2022-11-26 08:57:06

獲取自定義屬性的方法:

第一步:首先在標(biāo)簽上綁定上@click='getDateId(item.id)',并將屬性值傳到綁定的事件里面

第二步:在標(biāo)簽上繼續(xù)綁定:date-id = 'item.id'屬性

第三步:在<script>里面的屬性methods里面添寫上事件函數(shù) getDateId(id){} 在事件函數(shù)里面獲取id的值即可

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

補(bǔ)充知識(shí):vue本地存儲(chǔ)、獲取自定義data-id、獲取鏈接url參數(shù)、頁面跳轉(zhuǎn)返回、修改頁面title

一、本地存儲(chǔ):

localStorage.setItem(’uqid’,’REgaI2eAT9yDfpdc’); //存儲(chǔ)本地(傳死參)

var uqid = localStorage.getItem(’uqid’); // 獲取存儲(chǔ)本地值

或者

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參數(shù)

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

以上獲取url參數(shù)需要引入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參數(shù)

global.utils = utils;

四、頁面跳轉(zhuǎn)返回

@click='bindReturn'methods:{ bindReturn(){ this.$router.go(-1); //返回上一頁, }, bindOrider(){ this.$router.push({path: ’/doctorlist’}); //頁面跳轉(zhuǎn) },}

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 最后添加

// 修改頁面titlerouter.beforeEach((to, from, next) => { /* 路由發(fā)生變化修改頁面title */ if (to.meta.title) { document.title = to.meta.title; } next();})

以上這篇在Vue中獲取自定義屬性方法:data-id的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 安泽县| 黄浦区| 韩城市| 红河县| 浦县| 盐池县| 瑞昌市| 徐州市| 潼南县| 根河市| 含山县| 报价| 浦北县| 河北区| 黔南| 洪雅县| 南靖县| 育儿| 如东县| 仙桃市| 江阴市| 汉川市| 大方县| 台中县| 同江市| 墨竹工卡县| 遂平县| 中西区| 和林格尔县| 株洲县| 自贡市| 萨迦县| 黔江区| 巢湖市| 平定县| 确山县| 介休市| 连城县| 云安县| 囊谦县| 北安市|