我有一个方法需要创建一个字符串,其中包含
基本 URL /get-it
和一些随机生成的字符串?
methods:{
GenerateURL(){
...
}
}
怎样才能实现?如何使用 vue 路由器获取基本 URL 或/get-it 但不导航到空的/get-it 页面?我只需要将它用作组件内的字符串。
最佳答案
来自 docs :
$route.path
type: string
A string that equals the path of the current route, always resolved as an absolute path. e.g. "/foo/bar"
因此,在您的情况下,您可以执行以下操作:
methods:{
GenerateURL(){
var fullUrl = window.location.origin + this.$route.path + "/get-it/yourRandomString"
}
}
Location Origin .
关于vue.js - 如何使用 vue 路由器在 Vuejs 方法中获取 baseURL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63401547/