fix: 🐛 删除Editor双向绑定,改为props传参

This commit is contained in:
chenkl 2020-12-24 16:55:31 +08:00
parent 5142e6e323
commit c395e27f67
32 changed files with 53 additions and 167 deletions

View File

@ -33,7 +33,7 @@
"vue": "3.0.4", "vue": "3.0.4",
"vue-router": "4.0.0-rc.6", "vue-router": "4.0.0-rc.6",
"vuex": "4.0.0-rc.2", "vuex": "4.0.0-rc.2",
"wangeditor": "^4.5.2", "wangeditor": "4.5.4",
"web-storage-cache": "^1.1.1" "web-storage-cache": "^1.1.1"
}, },
"devDependencies": { "devDependencies": {

View File

@ -11,7 +11,7 @@ import 'highlight.js/styles/monokai-sublime.css'
export default defineComponent({ export default defineComponent({
name: 'Editor', name: 'Editor',
props: editorProps, props: editorProps,
emits: ['change', 'focus', 'blur', 'update:value'], emits: ['change', 'focus', 'blur', 'update:modelValue'],
setup(props, { emit }) { setup(props, { emit }) {
const editorRef = ref<HTMLElement | null>(null) const editorRef = ref<HTMLElement | null>(null)
const editor = ref<E | null>(null) const editor = ref<E | null>(null)
@ -101,8 +101,8 @@ export default defineComponent({
// onchange // onchange
editor.config.onchange = (html: string) => { editor.config.onchange = (html: string) => {
const text = editor.txt.text() const text = editor.txt.text()
emitFun(editor, html, 'change') emitFun(editor, props.valueType === 'html' ? html : text, 'change')
emit('update:value', props.valueType === 'html' ? html : text) // emit('update:modelValue', props.valueType === 'html' ? html : text)
} }
// onchange 200ms // onchange 200ms
editor.config.onchangeTimeout = onchangeTimeout editor.config.onchangeTimeout = onchangeTimeout
@ -121,8 +121,21 @@ export default defineComponent({
emit(type, props.valueType === 'html' ? html : text) emit(type, props.valueType === 'html' ? html : text)
} }
function getHtml() {
if (editor.value) {
return unref(editor.value as any).txt.html()
}
}
function getText() {
if (editor.value) {
return unref(editor.value as any).txt.text()
}
}
return { return {
editorRef editorRef,
getHtml, getText
} }
} }
}) })

View File

@ -14,7 +14,7 @@ export const editorProps = {
zIndex: 0, zIndex: 0,
placeholder: '请输入文本', placeholder: '请输入文本',
focus: false, focus: false,
onchangeTimeout: 500, onchangeTimeout: 1000,
customAlert: (s: string, t: string) => { customAlert: (s: string, t: string) => {
switch (t) { switch (t) {
case 'success': case 'success':

View File

@ -1,6 +1,10 @@
import type { App } from 'vue' import type { App } from 'vue'
import Dialog from './Dialog/index.vue'// Dialog组件 import Dialog from './Dialog/index.vue'// Dialog组件
import ComTable from './Table/index.vue'// Table组件
import ComSearch from './Search/index.vue'// Search组件
export function setupGlobCom(app: App<Element>): void { export function setupGlobCom(app: App<Element>): void {
app.component('ComDialog', Dialog) app.component('ComDialog', Dialog)
app.component('ComTable', ComTable)
app.component('ComSearch', ComSearch)
} }

View File

@ -7,12 +7,17 @@
type="info" type="info"
style="margin-bottom: 20px;" style="margin-bottom: 20px;"
/> />
<editor v-model:value="html" /> <editor ref="editorRef" :value="html" />
<div style="text-align: center;margin-top: 20px;">
<el-button @click="getContent('getHtml')">获取HTML(请在控制台查看)</el-button>
<el-button @click="getContent('getText')">获取TEXT(请在控制台查看)</el-button>
</div>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref, unref } from 'vue'
import Editor from '_c/Editor/index.vue' import Editor from '_c/Editor/index.vue'
import { content } from './data' import { content } from './data'
export default defineComponent({ export default defineComponent({
@ -22,8 +27,16 @@ export default defineComponent({
}, },
setup() { setup() {
const html = ref<string>(content) const html = ref<string>(content)
const editorRef = ref<HTMLElement | null>(null)
function getContent(name: string) {
console.log(unref(editorRef as any)[name]())
}
return { return {
html html,
editorRef,
getContent
} }
} }
}) })

View File

@ -48,7 +48,7 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import { createImgPreview } from '_c/Preview/functional' import { createImgPreview } from '_c/Preview'
import { Message } from '_c/Message' import { Message } from '_c/Message'
export default defineComponent({ export default defineComponent({
// name: 'PreviewDemo', // name: 'PreviewDemo',

View File

@ -1,59 +0,0 @@
<template>
<div>
<el-alert message="抽取于 Element 的 Scrollbar 组件进行改造统一美化各个浏览器滚动条,保持一致性。" style="margin-bottom: 20px;" />
<el-alert message="横向滚动,外围容器需要设置固定宽度。" style="margin-bottom: 20px;" />
<div class="deom__wrap deom__wrap--horizontal">
<scrollbar>
<ul class="deom-ul__wrap">
<li v-for="i in 1" :key="i">{{ i }}</li>
</ul>
</scrollbar>
</div>
<el-alert message="纵向滚动,外围容器需要设置固定高度。" style="margin-bottom: 20px;margin-top: 20px;" />
<div class="deom__wrap deom__wrap--vertical">
<scrollbar>
<ul class="deom-ul__wrap">
<li v-for="i in 100" :key="i">{{ i }}</li>
</ul>
</scrollbar>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import Scrollbar from '_c/Scrollbar/index.vue'
export default defineComponent({
// name: 'Scroll',
components: {
Scrollbar
}
})
</script>
<style lang="less" scoped>
.deom__wrap {
padding: 20px;
background: #fff;
li {
border: 1px solid #91d5ff;
height: 40px;
line-height: 40px;
margin-bottom: -1px;
padding-left: 15px;
}
}
.deom__wrap--horizontal {
width: 500px;
height: 80px;
.deom-ul__wrap {
width: 800px;
}
}
.deom__wrap--vertical {
width: 500px;
height: 500px;
}
</style>

View File

@ -15,7 +15,7 @@
style="margin-bottom: 20px;margin-top: 20px;" style="margin-bottom: 20px;margin-top: 20px;"
/> />
<div class="searh"> <div class="searh">
<search <com-search
:data="classicData" :data="classicData"
@search-submit="searchSubmit1" @search-submit="searchSubmit1"
@reset-submit="resetSubmit1" @reset-submit="resetSubmit1"
@ -33,7 +33,7 @@
style="margin-bottom: 20px;margin-top: 20px;" style="margin-bottom: 20px;margin-top: 20px;"
/> />
<div class="searh"> <div class="searh">
<search <com-search
layout="bottom" layout="bottom"
:data="classicData" :data="classicData"
@search-submit="searchSubmit2" @search-submit="searchSubmit2"
@ -52,7 +52,7 @@
style="margin-bottom: 20px;margin-top: 20px;" style="margin-bottom: 20px;margin-top: 20px;"
/> />
<div class="searh"> <div class="searh">
<search <com-search
layout="right" layout="right"
:data="classicData" :data="classicData"
@search-submit="searchSubmit3" @search-submit="searchSubmit3"
@ -67,13 +67,9 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import Search from '_c/Search/index.vue'
import { classicData } from './classic-data' import { classicData } from './classic-data'
export default defineComponent({ export default defineComponent({
// name: 'SearchDemo', // name: 'SearchDemo',
components: {
Search
},
setup() { setup() {
const formData1 = ref<{[key: string]: any} | null>(null) const formData1 = ref<{[key: string]: any} | null>(null)
const formData2 = ref<{[key: string]: any} | null>(null) const formData2 = ref<{[key: string]: any} | null>(null)

View File

@ -48,7 +48,7 @@
</el-col> </el-col>
<el-col :span="24"> <el-col :span="24">
<el-form-item prop="content" label="内容"> <el-form-item prop="content" label="内容">
<editor v-model:value="form.content" /> <editor ref="editorRef" :value="form.content" />
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
@ -87,6 +87,7 @@ export default defineComponent({
emits: ['close', 'success'], emits: ['close', 'success'],
setup(props, { emit }) { setup(props, { emit }) {
const formRef = ref<HTMLElement | null>(null) const formRef = ref<HTMLElement | null>(null)
const editorRef = ref<HTMLElement | null>(null)
const subLoading = ref<boolean>(false) const subLoading = ref<boolean>(false)
const form = reactive<InfoWriteParams>({ const form = reactive<InfoWriteParams>({
@ -136,6 +137,8 @@ export default defineComponent({
// //
function setListData() { function setListData() {
const formRefWrap = unref(formRef as any) const formRefWrap = unref(formRef as any)
const editorRefWrap = unref(editorRef as any)
form.content = editorRefWrap.getHtml()
try { try {
subLoading.value = true subLoading.value = true
formRefWrap.validate(async(valid: boolean) => { formRefWrap.validate(async(valid: boolean) => {
@ -166,7 +169,7 @@ export default defineComponent({
} }
return { return {
formRef, formRef, editorRef,
subLoading, subLoading,
form, form,
rules, rules,

View File

@ -1,7 +1,7 @@
<template> <template>
<div> <div>
<div class="search__example--wrap"> <div class="search__example--wrap">
<search <com-search
:data="searchData" :data="searchData"
@search-submit="searchSubmit" @search-submit="searchSubmit"
@reset-submit="resetSubmit" @reset-submit="resetSubmit"
@ -58,8 +58,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
import Search from '_c/Search/index.vue'
import IfnoWrite from './components/IfnoWrite.vue' import IfnoWrite from './components/IfnoWrite.vue'
import { useExample } from '@/hooks/useExample' import { useExample } from '@/hooks/useExample'
@ -116,8 +114,6 @@ const columns = [
export default defineComponent({ export default defineComponent({
// name: 'Example', // name: 'Example',
components: { components: {
ComTable,
Search,
IfnoWrite IfnoWrite
}, },
setup() { setup() {

View File

@ -13,7 +13,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -52,9 +51,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'BasicTable', // name: 'BasicTable',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -18,7 +18,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -57,9 +56,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'BorderTable', // name: 'BorderTable',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -36,7 +36,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -78,9 +77,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'CustomHeader', // name: 'CustomHeader',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -17,7 +17,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const tableData = [ const tableData = [
{ {
@ -41,9 +40,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'CustomIndex', // name: 'CustomIndex',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -44,7 +44,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -106,9 +105,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'ExpandRow', // name: 'ExpandRow',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -25,7 +25,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -139,9 +138,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'FixedColumnHeader', // name: 'FixedColumnHeader',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -24,7 +24,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -106,9 +105,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'FixedColumn', // name: 'FixedColumn',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -19,7 +19,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -76,9 +75,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'FixedHeader', // name: 'FixedHeader',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -24,7 +24,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -70,9 +69,6 @@ const columns = [
] ]
export default defineComponent({ export default defineComponent({
// name: 'FluidHeight', // name: 'FluidHeight',
components: {
ComTable
},
setup() { setup() {
const tableData = ref<any[]>([ const tableData = ref<any[]>([
{ {

View File

@ -28,7 +28,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -115,9 +114,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'MergeTable', // name: 'MergeTable',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -24,7 +24,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -82,9 +81,6 @@ const columns = [
export default defineComponent({ export default defineComponent({
// name: 'MultiHeader', // name: 'MultiHeader',
components: {
ComTable
},
setup() { setup() {
const tableData = ref<any[]>([ const tableData = ref<any[]>([
{ {

View File

@ -25,7 +25,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref, unref } from 'vue' import { defineComponent, ref, unref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -64,9 +63,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'MultipleChoice', // name: 'MultipleChoice',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -23,7 +23,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -62,9 +61,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'PageTable', // name: 'PageTable',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -29,7 +29,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref, unref } from 'vue' import { defineComponent, ref, unref } from 'vue'
import ComTable from '_c/Table/index.vue'
const tableData = [ const tableData = [
{ {
@ -57,9 +56,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'ScreenTable', // name: 'ScreenTable',
components: {
ComTable
},
setup() { setup() {
const filterTable = ref<HTMLElement | null>(null) const filterTable = ref<HTMLElement | null>(null)

View File

@ -25,7 +25,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref, unref } from 'vue' import { defineComponent, ref, unref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -64,9 +63,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'SingleChoice', // name: 'SingleChoice',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -19,7 +19,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -60,9 +59,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'SortTable', // name: 'SortTable',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -18,7 +18,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -57,9 +56,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'StateTable', // name: 'StateTable',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -18,7 +18,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -57,9 +56,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'StripeTable', // name: 'StripeTable',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -30,7 +30,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -117,9 +116,6 @@ const tableData = [
export default defineComponent({ export default defineComponent({
// name: 'TotalTable', // name: 'TotalTable',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -33,7 +33,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref } from 'vue' import { defineComponent, ref } from 'vue'
import ComTable from '_c/Table/index.vue'
const columns = [ const columns = [
{ {
@ -138,9 +137,6 @@ const tableData1 = [
export default defineComponent({ export default defineComponent({
// name: 'TreeAndLoad', // name: 'TreeAndLoad',
components: {
ComTable
},
setup() { setup() {
const loading = ref<boolean>(true) const loading = ref<boolean>(true)
setTimeout(() => { setTimeout(() => {

View File

@ -10550,10 +10550,10 @@ vuex@4.0.0-rc.2:
resolved "https://registry.yarnpkg.com/vuex/-/vuex-4.0.0-rc.2.tgz#3681c84eb6f5171b039edaa17cc78105e20724f3" resolved "https://registry.yarnpkg.com/vuex/-/vuex-4.0.0-rc.2.tgz#3681c84eb6f5171b039edaa17cc78105e20724f3"
integrity sha512-HCPzYGea1xL7fMpDoMiHKujC1Bi/HM9LS5ML0Kv55zQtZJvOl0Lq7eWvJoen+SI4Lf7p9V5AqcVsoLPXNBywjg== integrity sha512-HCPzYGea1xL7fMpDoMiHKujC1Bi/HM9LS5ML0Kv55zQtZJvOl0Lq7eWvJoen+SI4Lf7p9V5AqcVsoLPXNBywjg==
wangeditor@^4.5.2: wangeditor@4.5.4:
version "4.5.3" version "4.5.4"
resolved "https://registry.yarnpkg.com/wangeditor/-/wangeditor-4.5.3.tgz#a646a222ecd3ec81fef845efbfb57ece864ecc2c" resolved "https://registry.yarnpkg.com/wangeditor/-/wangeditor-4.5.4.tgz#cce6f73b96fdb9ce1f19a1e972e1fd0aef9192a6"
integrity sha512-fxByLI/RPtvc23dSz8P9I9cywDwCugoFKn/xq/wi6fuTlrI7SMUBSGM655U4stwkK3oRljPRt0kWYGeR3ScyuQ== integrity sha512-HqqyPzpf03E2VO7qtOz2nUCr7GT75/+9agvQnG5Ybiwu9FcwGkVipn9BdVxydBxfAeRGCXXWs6+v3Z9dJ0H2fg==
dependencies: dependencies:
"@babel/runtime" "^7.11.2" "@babel/runtime" "^7.11.2"
"@babel/runtime-corejs3" "^7.11.2" "@babel/runtime-corejs3" "^7.11.2"