feat: 切换文件时不要触发 markdown code 的变更事件
This commit is contained in:
parent
c590500d19
commit
8586dcc320
@ -79,8 +79,10 @@ watch(rootFolderPath, (newRootPath) => {
|
|||||||
|
|
||||||
// <FolderTree> 完成文件树渲染后,点击文件得到 currentFilePath
|
// <FolderTree> 完成文件树渲染后,点击文件得到 currentFilePath
|
||||||
const currentFilePath = ref(localStorage.getItem('currentSelectedFilePath') || "");
|
const currentFilePath = ref(localStorage.getItem('currentSelectedFilePath') || "");
|
||||||
|
let switchFilePath = false; // 切换文件时,避免触发 markdownCode 的 watch 事件
|
||||||
// 读取 currentFilePath 的文件内容,填充到 MarkdownEditor 之中
|
// 读取 currentFilePath 的文件内容,填充到 MarkdownEditor 之中
|
||||||
watch(currentFilePath, async (newFilePath) => {
|
watch(currentFilePath, async (newFilePath) => {
|
||||||
|
switchFilePath = true;
|
||||||
localStorage.setItem('currentSelectedFilePath', newFilePath);
|
localStorage.setItem('currentSelectedFilePath', newFilePath);
|
||||||
await readFileContent(newFilePath);
|
await readFileContent(newFilePath);
|
||||||
})
|
})
|
||||||
@ -94,6 +96,10 @@ const getFileNameFromFilePath = (filePath) => {
|
|||||||
const mainEditor = ref(null);
|
const mainEditor = ref(null);
|
||||||
const markdownCode = ref("# Hello Markdown");
|
const markdownCode = ref("# Hello Markdown");
|
||||||
watch(markdownCode, (newMarkdownCode) => {
|
watch(markdownCode, (newMarkdownCode) => {
|
||||||
|
if (switchFilePath === true) {
|
||||||
|
switchFilePath = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.log("code be updated");
|
console.log("code be updated");
|
||||||
})
|
})
|
||||||
async function readFileContent(filePath) {
|
async function readFileContent(filePath) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user