programing

Vue.js 라우터: $route.router.go()가 작동하지 않는 이유는?

prostudy 2022. 3. 23. 00:22
반응형

Vue.js 라우터: $route.router.go()가 작동하지 않는 이유는?

vue-router 0.7.13 + SweetAlert가 있는 페이지로 리디렉션되지 않는 이유난 이렇게 좋아해 (라벨 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)

참조URL: https://stackoverflow.com/questions/40702309/vue-js-router-why-route-router-go-not-working

반응형