vue.js - 在 axios Post 之后 router.push , Vuejs
问题描述
在发出发布请求后,我尝试重定向,我尝试了不同的方法,但到目前为止没有任何效果。
self.$router.push('/record')
Vue.$router.push('/record')
this.$router.push({ name: 'Record' })
这是更新的代码。带有 axios 表单组件,app.js 和 main.js
axios.delete('/record/' + this.id)
.then((response) => {
this.$router.push('/record')
});
})
.catch(error => {
//
});
在我的 app.js
import VueRouter from "vue-router";
import router from "./router";
Vue.use(VueRouter);
new Vue({
router,
render: h => h(App)
}).$mount("#app");
路由器.js
import Vue from "vue";
import VueRouter from "vue-router";
import Record from './components/AddPerson';
Vue.use(VueRouter);
const routes = [
{
path: "/record",
name: "Record",
component: Record,
},
];
const router = new VueRouter({
mode: "history",
base: process.env.BASE_URL,
routes
});
export default router;
解决方案
您是否尝试重定向到相同的路线?
Vue 缓存组件,因为这样更快。
如果这是您的问题,您必须执行以下操作:
<template>
<v-app>
<router-view :key="$route.fullPath" />
</v-app>
</template>
<script>
export default {
name: 'App',
};
</script>
axios
.delete(`/record/${this.id}`)
.then(response => {
this.$router.push({
name: 'Record',
query: { x: new Date().toISOString() },
});
})
.catch(error => {
//
});
推荐阅读
- url - Java 如何将 URL 格式化为字符串以连接 JSoup Malformed URL 错误
- excel - 为什么使用 Power Pivot 在 Excel 中删除数据模型?
- c# - 使用 AWS S3 TransferUtility 的内存使用率高且上传速度慢
- mysql - mysql搜索具有动态字数的3列
- apache-spark - 使用 Typesafe 配置时在 Spark YARN 客户端和集群模式之间切换
- java - In GAE Java Standard environment how to scale based on memory consumption?
- aws-api-gateway - 为单个键映射 x-amazon-apigateway-integration.requestParameters 的多个值?
- python - 没有名为“cv2”的模块?
- html - 使用 Flex 创建三个带有内容的响应式、垂直堆叠和垂直可滚动的 div
- python - 蟒蛇 | MYSQL - 错误 1064:您的 SQL 语法有错误