vue.js 1018 字节
Newer Older
1 2 3
// 使用白名单过滤(前期有一批自定义组件使用了 uni-)
import tags from 'uni-helpers/tags'

fxy060608's avatar
fxy060608 已提交
4 5 6 7 8 9
import {
  hasLifecycleHook
} from 'uni-helpers/index'

export default function initVue (Vue) {
  Vue.config.errorHandler = function (err) {
10
    const app = typeof getApp === 'function' && getApp()
fxy060608's avatar
fxy060608 已提交
11 12 13 14 15 16 17
    if (app && hasLifecycleHook(app.$options, 'onError')) {
      app.__call_hook('onError', err)
    } else {
      console.error(err)
    }
  }

fxy060608's avatar
init v3  
fxy060608 已提交
18
  const oldIsReservedTag = Vue.config.isReservedTag
19

fxy060608's avatar
init v3  
fxy060608 已提交
20 21 22
  Vue.config.isReservedTag = function (tag) {
    return tags.indexOf(tag) !== -1 || oldIsReservedTag(tag)
  }
23

fxy060608's avatar
init v3  
fxy060608 已提交
24
  Vue.config.ignoredElements = tags
25

fxy060608's avatar
init v3  
fxy060608 已提交
26
  const oldGetTagNamespace = Vue.config.getTagNamespace
27

fxy060608's avatar
init v3  
fxy060608 已提交
28
  const conflictTags = ['switch', 'image', 'text', 'view']
29

fxy060608's avatar
init v3  
fxy060608 已提交
30 31 32 33 34
  Vue.config.getTagNamespace = function (tag) {
    if (~conflictTags.indexOf(tag)) { // svg 部分标签名称与 uni 标签冲突
      return false
    }
    return oldGetTagNamespace(tag) || false
35 36
  }
}