路泰科技体检小程序UI设计新版本
1
wwl
5 天以前 a6cdbcfe28fcc40ebb4919f57d60fb20122e8e57
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
 * @fileoverview 插件入口文件模板
 */
 
const data = {} // 全局数据
 
/**
 * @description 组件被创建时将实例化插件
 * @param {Component} vm 组件实例
 */
function Plugin (vm) {
  this.vm = vm // 保存实例在其他周期使用
  this.compData = {} // 仅在单个组件中使用的数据
  data.xxx = 'xxx' // 记录全局数据
}
 
/**
 * @description html 数据更新时触发
 * @param {string} content 要更新的 html 字符串
 * @param {object} config 解析配置
 * @returns {string|void} 如果要对 html 字符串进行一些预处理,则返回处理后的字符串
 */
Plugin.prototype.onUpdate = function (content, config) {
  config.ignoreTags.xxx = true // 移除 xxx 标签
  // 对 html 内容进行预处理并返回修改,没有修改则不需要返回
  return content
}
 
/**
 * @description 解析到一个标签时触发
 * @param {object} node 标签
 * @param {object} parser 解析器实例
 * @returns {boolean|void} 如果返回 false 将移除该标签
 */
Plugin.prototype.onParse = function (node, parser) {
  // 处理文本标签
  if (node.type === 'text') {
    // node.text 文本内容
  } else {
    // 处理元素标签
    // node.name 标签名
    // node.attrs 属性列表
    // node.children 子节点(非自闭合标签有)
 
    if (node.name === 'xxx') {
      parser.expose() // 如果该标签不能被 rich-text 包含,需要调用此方法暴露出来
      // parser.options 组件传入的一些解析属性
      // parser.stack 可以从栈中获取祖先节点
    }
  }
}
 
/**
 * @description dom 树加载完毕时触发(load 事件)
 */
Plugin.prototype.onLoad = function () {
  // 可以获取媒体 context 对象等
}
 
/**
 * @description 组件被移除时触发
 */
Plugin.prototype.onDetached = function () {
  // 可以释放一些必要的资源(计时器等)
}
 
module.exports = Plugin