1
爲什麼沒有工作重定向到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
。
什麼可能是錯的?
我補充這app.js,但看看同樣的錯誤.. –
@VikkyShostak這可能不會解決問題,但值得注意的:'go'使用例如'go(1)'或'go(-1)'向前/向後跳轉,在你的情況下使用'this。$ router.push('/ articles')'。我測試了'go('/ articles')'以某種方式重新加載頁面。 –
@潘俊傑潘俊傑'push'方法在vue-router 0.7.13上工作? –