Why doesn't work redirect to page with vue-router 0.7.13 + SweetAlert ? I do like this (Laravel 5.3):
Here is article.blade.php
:
...
<a href="#" v-on:click.prevent="deleteArticle('/articles/{{ $article->id }}/delete')">Delete</a>
...
This is my 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');
});
});
});
}
}
});
And 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"
}
}
There is an error (from OS X Safari console): TypeError: undefined is not an object (evaluating 'self.$route.router')
.
I tried more like this: self.$router.go('/articles')
, but it show me same error. Somehow for him $route
(or $router
) as an undefined
.
What can be wrong?
You forgot to actually install the plugin:
var VueRouter = require ('vue-router')
Vue.use (VueRouter)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.