Vue.js 路由器:为什么 $route.router.go() 不工作?
Vue.js Router: why $route.router.go() not working?
为什么无法使用 vue-router 0.7.13 + SweetAlert 重定向到页面?我喜欢这个 (Laravel 5.3):
这里是article.blade.php
:
...
<a href="#" v-on:click.prevent="deleteArticle('/articles/{{ $article->id }}/delete')">Delete</a>
...
这是我的 app.js
:
window.Vue = require('vue');
window.VueRouter = require('vue-router');
Vue.use(VueRouter);
var article_form = new Vue({
el: '#article_form',
data: {
...
},
methods: {
...
...
deleteArticle: function (url) { // Click Delete button
var self = this;
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
}, function () { // Click Yes button
self.$http.delete(url).then(function () {
swal({
title: "Deleted!",
text: "Your imaginary file has been deleted.",
type: "success"
}, function () { // After click ОК must be redirect
self.$route.router.go('/articles');
});
});
});
}
}
});
和package.json
:
{
"private": true,
"scripts": {
"prod": "gulp --production",
"dev": "gulp watch"
},
"devDependencies": {
"gulp": "^3.9.1",
"laravel-elixir": "^6.0.0-14",
"laravel-elixir-webpack-official": "^1.0.9",
"vue-resource": "^1.0.3"
},
"dependencies": {
"sweetalert": "^1.1.3",
"vue": "^1.0.28",
"vue-router": "^0.7.13"
}
}
出现错误(来自 OS X Safari 控制台):TypeError: undefined is not an object (evaluating 'self.$route.router')
.
我尝试了更多类似的方法:self.$router.go('/articles')
,但它显示了同样的错误。不知何故对他来说 $route
(或 $router
)作为 undefined
.
有什么问题吗?
您忘记实际安装插件了:
var VueRouter = require ('vue-router')
Vue.use (VueRouter)
为什么无法使用 vue-router 0.7.13 + SweetAlert 重定向到页面?我喜欢这个 (Laravel 5.3):
这里是article.blade.php
:
...
<a href="#" v-on:click.prevent="deleteArticle('/articles/{{ $article->id }}/delete')">Delete</a>
...
这是我的 app.js
:
window.Vue = require('vue');
window.VueRouter = require('vue-router');
Vue.use(VueRouter);
var article_form = new Vue({
el: '#article_form',
data: {
...
},
methods: {
...
...
deleteArticle: function (url) { // Click Delete button
var self = this;
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
}, function () { // Click Yes button
self.$http.delete(url).then(function () {
swal({
title: "Deleted!",
text: "Your imaginary file has been deleted.",
type: "success"
}, function () { // After click ОК must be redirect
self.$route.router.go('/articles');
});
});
});
}
}
});
和package.json
:
{
"private": true,
"scripts": {
"prod": "gulp --production",
"dev": "gulp watch"
},
"devDependencies": {
"gulp": "^3.9.1",
"laravel-elixir": "^6.0.0-14",
"laravel-elixir-webpack-official": "^1.0.9",
"vue-resource": "^1.0.3"
},
"dependencies": {
"sweetalert": "^1.1.3",
"vue": "^1.0.28",
"vue-router": "^0.7.13"
}
}
出现错误(来自 OS X Safari 控制台):TypeError: undefined is not an object (evaluating 'self.$route.router')
.
我尝试了更多类似的方法:self.$router.go('/articles')
,但它显示了同样的错误。不知何故对他来说 $route
(或 $router
)作为 undefined
.
有什么问题吗?
您忘记实际安装插件了:
var VueRouter = require ('vue-router')
Vue.use (VueRouter)