fix: 文档无刷新的问题
This commit is contained in:
parent
36843fb304
commit
e724bc3326
@ -26,6 +26,18 @@ export default {
|
||||
await this.loadMarked();
|
||||
this.fetchMdContent();
|
||||
},
|
||||
// 外层 router-view 使用了 keep-alive:
|
||||
// 同一 path 仅 query 变化时组件不会重建,mounted 不会再次触发,
|
||||
// 所以必须监听 $route.query.file 来重新加载文档。
|
||||
watch: {
|
||||
'$route.query.file': {
|
||||
handler(newFile, oldFile) {
|
||||
if (newFile !== oldFile) {
|
||||
this.fetchMdContent();
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
loadMarked() {
|
||||
return new Promise((resolve) => {
|
||||
@ -53,6 +65,10 @@ export default {
|
||||
});
|
||||
},
|
||||
fetchMdContent() {
|
||||
// 每次重新加载前重置状态,避免上一次失败/旧内容残留
|
||||
this.loading = true;
|
||||
this.error = '';
|
||||
this.content = '';
|
||||
const { file } = this.$route.query;
|
||||
if (!file) {
|
||||
this.content = '# 未指定文件\n\n请使用 ?file=xxx 传递文件路径';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user