diff --git a/dist/index.html b/dist/index.html
index 5944b5130e580e2ff37dccd56c6610e34adf24d3..84cd03a1945eab1b766a98583e3b570d28165aa2 100644
--- a/dist/index.html
+++ b/dist/index.html
@@ -7,7 +7,7 @@
Document
diff --git a/src/main.js b/src/main.js
index 25a8d72a9b424c68a028bb3fac8cf5c8b9781f0e..02a761ee9b5a6724237611ceebacc57d23a830c2 100644
--- a/src/main.js
+++ b/src/main.js
@@ -8,8 +8,15 @@ import "@/assets/style/global.less";
Vue.use(Vtip.directive);
function initMdEditor(obj) {
- const {
+ const _this = this;
+ this.value = {
+ text: "",
+ html: ""
+ };
+ this.vEl = "";
+ let {
el,
+ onLoad = () => {},
onChange = () => {},
onUpload = () => {},
onFocus = () => {},
@@ -19,11 +26,11 @@ function initMdEditor(obj) {
placeholder,
value,
zIndex = 2000,
- rule,
- rows = 10,
+ filePathRule,
+ rows = 6,
maxLength,
showWordLimit,
- throttle,
+ throttle = 1000,
canPreview,
canAttachFile,
themeOptions,
@@ -32,45 +39,84 @@ function initMdEditor(obj) {
if (!el || !document.querySelector(el)) throw new Error("请指定容器");
if (isNotEmpty(themeOptions)) initStyle(themeOptions);
if (isNotEmpty(zIndex)) setzIndex(zIndex);
- new Vue({
+ const id = new Date().getTime() + "";
+ const props = {
+ canAttachFile,
+ value,
+ themeOptions,
+ filePathRule,
+ rows,
+ id,
+ throttle,
+ canPreview,
+ toolsOptions,
+ placeholder,
+ maxLength,
+ zIndex,
+ focus: false,
+ showWordLimit
+ };
+ const listeners = {
+ change(val) {
+ onChange(val);
+ _this.value = val;
+ },
+ input(val) {
+ onInput(val);
+ _this.value = val;
+ },
+ load(val) {
+ onLoad(val);
+ _this.value = val;
+ },
+ focus(val) {
+ onFocus(val);
+ _this.value = val;
+ },
+ blur(val) {
+ onBlur(val);
+ _this.value = val;
+ },
+ submit(val) {
+ onSubmit(val);
+ _this.value = val;
+ },
+ upload({ val, callback }) {
+ onUpload(val, function(res) {
+ callback(res);
+ });
+ }
+ };
+ this.vEl = new Vue({
render: h =>
h(App, {
- on: {
- change(val) {
- onChange(val);
- },
- input(val) {
- onInput(val);
- },
- focus(val) {
- onFocus(val);
- },
- blur(val) {
- onBlur(val);
- },
- submit(val) {
- onSubmit(val);
- },
- upload({ val, callback }) {
- onUpload(val, function(res) {
- callback(res);
- });
- }
- },
- props: {
- canAttachFile,
- value,
- rule,
- rows,
- throttle,
- canPreview,
- toolsOptions,
- placeholder,
- maxLength,
- showWordLimit
- }
+ on: listeners,
+ props: props
})
}).$mount(el);
+
+ this.getValue = function(callback) {
+ if (callback) {
+ callback(this.value);
+ }
+ return this.value;
+ };
+
+ this.setValue = function(val) {
+ if (!val) return;
+ props.value = val + "";
+ this.vEl.$forceUpdate();
+ };
+
+ this.focus = function() {
+ props.focus = true;
+ this.vEl.$forceUpdate();
+ };
+
+ this.blur = function() {
+ props.focus = false;
+ this.vEl.$forceUpdate();
+ };
}
window.MdEditor = initMdEditor;
diff --git a/webpack.config.js b/webpack.config.js
index a1830c2a7bbcd04f2c8ac71752f60d81f49c7d8e..a031c84598f31302a410a9f04a94a2fb8c52f46d 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -8,6 +8,7 @@ module.exports = {
},
devServer: {
contentBase: path.resolve(__dirname, "dist"),
+ host: '0.0.0.0',
open: true
},
resolve: {