main.js 946 字节
Newer Older
璃白.'s avatar
璃白. 已提交
1 2
import Vue from "vue";
import App from "./App";
璃白.'s avatar
璃白. 已提交
3
import store from "./store";
璃白.'s avatar
璃白. 已提交
4 5
import Vtip from "vtip";
import "vtip/lib/index.min.css";
G
guoweijia 已提交
6
import { initStyle, isNotEmpty, updateText } from "@/assets/js/utils";
璃白.'s avatar
璃白. 已提交
7 8
import "@/assets/style/global.less";

璃白.'s avatar
璃白. 已提交
9 10
Vue.use(Vtip.directive);

璃白.'s avatar
璃白. 已提交
11
function initMdEditor(obj) {
G
guoweijia 已提交
12
  const { el, onChange, onUpload, canAttachFile, themeOptions } = obj;
璃白.'s avatar
璃白. 已提交
13
  if (!el || !document.querySelector(el)) throw new Error("请指定容器");
璃白.'s avatar
璃白. 已提交
14 15 16
  if (isNotEmpty(themeOptions)) initStyle(themeOptions);
  if (isNotEmpty(canAttachFile))
    store.commit("setCanAttachFile", canAttachFile);
璃白.'s avatar
璃白. 已提交
17 18

  new Vue({
璃白.'s avatar
璃白. 已提交
19
    store,
G
guoweijia 已提交
20
    render: (h) =>
璃白.'s avatar
璃白. 已提交
21 22 23 24
      h(App, {
        on: {
          change(val) {
            onChange(val);
G
guoweijia 已提交
25 26 27 28 29
          },
          upload(val) {
            onUpload(val, function(res) {
              updateText("\n\n![img](", `${res})\n`);
            });
璃白.'s avatar
璃白. 已提交
30 31 32 33 34 35
          }
        }
      })
  }).$mount(el);
}

璃白.'s avatar
璃白. 已提交
36
window.MdEditor = initMdEditor;