admin管理员组文章数量:1397049
I'm making a post board with Vue.js and trying to make the page redirected when each post is clicked.
I've installed vue-route and axios.
In index.js,
export default new Router({
route: [
{
path: '/',
name: 'Post',
ponent: Post
},
{
path: '/:req_no',
name: 'Detail',
ponent: Detail
},
]
})
In post.vue
<div @click="detailPost(post.no)">{{post.title}}</div>
.
.
.
detailPost(req_no) {
this.$router.push({
path: `https://dataURL/detail.php/${req_no}`
})
}
In Detail.vue
<template>
<div>
{{contents}}
</div>
</template>
<script>
import axios from 'axios';
export default {
name: 'Datail',
data() {
return {
req_no: this.$route.params.req_no,
contents: {}
}
},
created() {
axios.get('https://dataURL/detail.php/', {
params: {
req_no: this.req_no
}
}).then(res => {
this.contents = this.res.data
});
}
}
</script>
I'm not sure where to put the url (in the function in post.Vue, detailPost() or in Detail.vue)
If I put it in the function, I get
http://localhost:8080/#/http://dataURL/detail.php/2
The API guide says I must use the params.
Could you please help me where to fix? Thanks alot!!
I'm making a post board with Vue.js and trying to make the page redirected when each post is clicked.
I've installed vue-route and axios.
In index.js,
export default new Router({
route: [
{
path: '/',
name: 'Post',
ponent: Post
},
{
path: '/:req_no',
name: 'Detail',
ponent: Detail
},
]
})
In post.vue
<div @click="detailPost(post.no)">{{post.title}}</div>
.
.
.
detailPost(req_no) {
this.$router.push({
path: `https://dataURL/detail.php/${req_no}`
})
}
In Detail.vue
<template>
<div>
{{contents}}
</div>
</template>
<script>
import axios from 'axios';
export default {
name: 'Datail',
data() {
return {
req_no: this.$route.params.req_no,
contents: {}
}
},
created() {
axios.get('https://dataURL/detail.php/', {
params: {
req_no: this.req_no
}
}).then(res => {
this.contents = this.res.data
});
}
}
</script>
I'm not sure where to put the url (in the function in post.Vue, detailPost() or in Detail.vue)
If I put it in the function, I get
http://localhost:8080/#/http://dataURL/detail.php/2
The API guide says I must use the params.
Could you please help me where to fix? Thanks alot!!
Share Improve this question asked May 16, 2019 at 4:12 Soomin ShinSoomin Shin 471 gold badge2 silver badges6 bronze badges 1-
The simplest thing would just be to put an anchor tag and
href=yourlink
– Michael Commented May 16, 2019 at 5:57
2 Answers
Reset to default 3You cannot use the router for a different domain.
See this answer: https://stackoverflow./a/41654493/146656
What you can do is simply use vanilla JS to do it:
window.location = `https://dataURL/detail.php/${req_no}`;
Is https://dataURL/detail.php
on same domain with your main app?
Please try:
this.$router.push({
path: `/detail.php/${req_no}`
})
If it's different domain, you can use window.location
window.location =
https://dataURL/detail.php/${req_no}
;
本文标签: javascriptHow to redirect in Vuejs to different url when clickedStack Overflow
版权声明:本文标题:javascript - How to redirect in Vue.js to different url when clicked? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744148371a2592945.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论