From de244ca6d9681ffed41655fc785ee9d0c8c99517 Mon Sep 17 00:00:00 2001 From: hulinneil <1289739946@qq.com> Date: Tue, 13 Nov 2018 19:04:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3md=E7=BC=96=E8=BE=91=E5=99=A8?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E5=9C=A8H5=E7=AB=AF=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E8=AD=A6=E5=91=8A=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ly-markdown/ly-markdown.vue | 56 ++++++++++--------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/examples/hello-uniapp/components/ly-markdown/ly-markdown.vue b/examples/hello-uniapp/components/ly-markdown/ly-markdown.vue index 485ac49258..6a9df5463b 100644 --- a/examples/hello-uniapp/components/ly-markdown/ly-markdown.vue +++ b/examples/hello-uniapp/components/ly-markdown/ly-markdown.vue @@ -19,12 +19,12 @@ - + - + - + @@ -41,7 +41,9 @@ data: function () { return { screenHeight: 0, - cursor: 0 + cursor: 0, + textareaDataSync:this.textareaData, + textareaHtmlSync:this.textareaHtml } }, props: { @@ -83,64 +85,64 @@ }, toolBarClick(type) { if (type == 'bold') { - this.textareaData += "**粗体文字** " + this.textareaDataSync += "**粗体文字** " } else if (type == "italic") { - this.textareaData += "*斜体* " + this.textareaDataSync += "*斜体* " } else if (type == "header") { uni.showActionSheet({ itemList: ["标题1", "标题2", "标题3", "标题4", "标题5", "标题6"], success: res => { switch (res.tapIndex) { case 0: - this.textareaData += "# 标题1\r"; + this.textareaDataSync += "# 标题1\r"; return; case 1: - this.textareaData += "## 标题2\r"; + this.textareaDataSync += "## 标题2\r"; return; case 2: - this.textareaData += "### 标题3\r"; + this.textareaDataSync += "### 标题3\r"; return; case 3: - this.textareaData += "#### 标题4\r"; + this.textareaDataSync += "#### 标题4\r"; return; case 4: - this.textareaData += "##### 标题5\r"; + this.textareaDataSync += "##### 标题5\r"; return; case 5: - this.textareaData += "###### 标题6\r"; + this.textareaDataSync += "###### 标题6\r"; return; } } }) } else if (type == "underline") { - this.textareaData += "++下划线++ " + this.textareaDataSync += "++下划线++ " } else if (type == "strike") { - this.textareaData += "~~中划线~~ " + this.textareaDataSync += "~~中划线~~ " } else if (type == "sup") { - this.textareaData += "^上角标^ " + this.textareaDataSync += "^上角标^ " } else if (type == "sub") { - this.textareaData += "~下角标~ " + this.textareaDataSync += "~下角标~ " } else if (type == "alignleft") { - this.textareaData += "\n::: hljs-left\n\n左对齐\n\n:::\n" + this.textareaDataSync += "\n::: hljs-left\n\n左对齐\n\n:::\n" } else if (type == "aligncenter") { - this.textareaData += "\n::: hljs-center\n\n居中对齐\n\n:::\n" + this.textareaDataSync += "\n::: hljs-center\n\n居中对齐\n\n:::\n" } else if (type == "alignright") { - this.textareaData += "\n::: hljs-right\n\n\n\n右对齐\n\n:::\n" + this.textareaDataSync += "\n::: hljs-right\n\n\n\n右对齐\n\n:::\n" } else if (type == "link") { - this.textareaData += "[在此输入网址描述](在此输入网址) " + this.textareaDataSync += "[在此输入网址描述](在此输入网址) " } else if (type == "imgage") { - this.textareaData += "![](在此输入图片地址) " + this.textareaDataSync += "![](在此输入图片地址) " } else if (type == "code") { - this.textareaData += "\n``` 代码块 \n\n```\n" + this.textareaDataSync += "\n``` 代码块 \n\n```\n" } else if (type == "table") { - this.textareaData += "\n|列1|列2|列3|\n|-|-|-|\n|单元格1|单元格2|单元格3|\n" + this.textareaDataSync += "\n|列1|列2|列3|\n|-|-|-|\n|单元格1|单元格2|单元格3|\n" } else if (type == "clear") { uni.showModal({ title: "提示", content: "确定清空?", success: res => { if (res.confirm) { - this.textareaData = ""; + this.textareaDataSync = ""; } } }) @@ -152,10 +154,10 @@ } }, watch: { - "textareaData": function (newValue, oldValue) { - this.textareaHtml = marked(newValue) + "textareaDataSync": function (newValue, oldValue) { + this.textareaHtmlSync = marked(newValue) this.$emit('update:textareaData', newValue) - this.$emit('update:textareaHtml', this.textareaHtml) + this.$emit('update:textareaHtml', this.textareaHtmlSync) } }, mounted: function () { -- GitLab