鍍金池/ 問答/HTML/ 插件注入出現(xiàn)的錯誤

插件注入出現(xiàn)的錯誤

之前在別的項目制作過一個alert彈窗,可以使用,但是換到另一個項目卻不行,點擊按鈕時出現(xiàn)異常:

 Failed to mount component: template or render function not defined.
(found in <Root>)

對應代碼:

    sigelDownLoad(signedCdnUrl) { // 單文件下載
      if (!signedCdnUrl) {
        this.$alert({
          title: '',
          height: 190 + 'px',
          content: '<span class="warn"><i class="iconfont icon-tanhao" style="vertical-align: -7px;"></i></span><span class="content" style="text-indent: 8px;">對方還沒上傳完成,請稍候。</span>',
          theme: '',
          button: false,
          confirmCallBack: function() {},
          closeBtnCB: function() {}
        })
      } else {
        let a = document.createElement('a')
        a.href = signedCdnUrl
        a.target = '_blank'
        a.setAttribute('download', '')
        a.click()
      }
    }

具體報錯提示,

clipboard.png

我的alert.js:

import Vue from 'vue'
import {
  isObject,
  hasOwnProperty
} from 'common/js/mixin'
const AlertConstructor = Vue.extend((require('./alert.vue')))
let instance
const Alert = (options = {}) => {
  if (Vue.prototype.$isServer) {
    return
  }
  if (!isObject(options)) {
    return
  }
  const requiredProps = ['content', 'button']
  for (let i = 0, j = requiredProps.length; i < j; i++) {
    if (!hasOwnProperty(options, requiredProps[i])) {
      throw Error(`Missed required prop:${requiredProps[i]}`)
    }
  }
  instance = new AlertConstructor({
    data: options
  })
  instance = instance.$mount()
  document.body.appendChild(instance.$el)
  return instance
}
Vue.prototype.$alert = (options) => {
  return Alert(options)
}
export default Alert

求解答,整個VUE能正常渲染,只是執(zhí)行$alert的時候有問題

回答
編輯回答
萌小萌

你的 alert 組件寫的有問題, 建議使用常規(guī)的格式書寫

2018年6月17日 01:17
編輯回答
拮據(jù)

如果你 import Vue from 'vue' 那么只能運行時編譯
詳見官方教程:運行時-編譯器-vs-只包含運行時
解決辦法也詳見上面的鏈接

2018年9月2日 15:40