vuejs这个。$ route不行

时间:2017-12-12 19:18:51

标签: vue.js vue-router

当我向api发送删除请求时,它运行良好,  但下一步我想重新编写索引,  所以我使用此代码**strong text**elif x.upper()=="Y": k=input("Enter the 1st letter of the name (upper-Case):") y=open("Names.txt","r") for i in y.readlines(): if k.upper() in i: print (i[:-1]) #need option if no search results are found ,但它不起作用

index.vue

sqlSave(access, Contracts_CurrMth, "T_Contracts", append=TRUE, rownames=FALSE, fast=FALSE, safer=TRUE, verbose=TRUE)

index.js

this.$router.push('/');

2 个答案:

答案 0 :(得分:0)

 deleteUser: function(user) {
     axios.delete('api/users/'+user.id).then(response => {
         this.$router.push({
             path: '/'
         });
     })

 }

你必须使用像这样的routeObject。 希望这一切都好。我没有看到任何其他错误。

更新:您正在使用多个vue实例。据我所知,这不好。页眉和页脚应该是主应用程序中包含的组件。我不知道你的httpVueLoader。

答案 1 :(得分:-1)

由于我不太明白你为什么要创建多个Vue.js实例,所以有一种方法可以实现这一点。

不是仅使用:new Vue()创建Vue实例,而是将其分配给全局变量:var vm1 = new Vue()。这样,您就可以通过vm1访问该Vue模型。

// You probably have to assign it to the window object => window.vueApp = vueApp, because of the module bundler
var vueApp = new Vue({
    el: '#app',
    router:router,
    template: '<router-view></router-view>',
});

var vueFoot = new Vue({
    el: '#foot',
    components: {
      'myfooter'   : httpVueLoader('js/components/footer.vue'),
    }
});

var vueHead = new Vue({
    el: '#head',
    components: {
      'myheader'   : httpVueLoader('js/components/header.vue'),
    }
});

在你的一个Vue组件中:

<script>
export default {
    // ...
    methods: {
        changeRoute() {
            vueApp.$router.push(); // 
        }
    },
}
</script>

我没有测试过,但你明白了。

您还可以导入路由器并在该实例上调用push方法。查看this answer

我会坚持使用该答案的解决方案并创建一个小辅助函数。像redirect()这样的东西。每当我需要将用户重定向到某个东西时,这个功能就会解决这个问题。