vue.js - 从 VUEJS 中的 url 获取 ID
问题描述
我目前正在学习 VUEJS,对此我完全陌生。所以我需要帮助。我想从 URL 中获取 ID,例如:
网址:
abc.net/dashboard/a/123456789
我想要123456789
文本格式。
解决方案
如果您正在使用,这可以指导您vue-router
import Vue from 'vue';
import VueRouter from 'vue-router';
import DashboardComponent from "./path/DashboardComponent";
Vue.use(VueRouter);
export default new VueRouter({
routes: [
{ path: '/dashboard/a/:id', component: DashboardComponent }//where :id is the dynamic id you wish to access from the browser
]
})
在你的DashboardComponent
<template>
<div>
{{id}} //this will show the id in plain text
</div>
</template>
<script>
export default {
name: 'Dashboard',
data(){
return {
id: this.$route.params.id //this is the id from the browser
}
},
}
</script>
推荐阅读
- javascript - 在 IIFE 内执行后,函数返回没有返回正确的值
- python - 遍历数据框列表,对每个数据框的某些列执行计算,产生新的结果数据框
- javascript - 未处理的承诺拒绝警告
- date - 使用 Arrayformula 或 LOOKUP 填充日历
- ffmpeg - 尝试识别全局元数据
- c - 为什么声明的数组大小不会影响可以存储在数组中的输入的大小?
- python - python - 如何在python Telebot API中的命令后回复消息
- html - im getting that type of error send_mail got multiple values for argument fail_silently
- javascript - 如何将(mongo)数据库中的数据显示到网页 html
- javascript - 如何将 JS 和 JSON 一起编译?