vue-vnode-hook

2.0.0 • Public • Published

vue-vnode-hook

Installation

npm i vue-vnode-hook -S

Examples

install

import Vue from 'vue'
import VNodeHook from 'vue-vnode-hook'

Vue.use(VNodeHook)

register hooks

  • global hook (root component)
const app = new Vue({
  render: h => h(App),
})

app.$vnhook.register({
  tag: 'el-column',
  beforeCreate(ctx, data, children) {
    // do something

    // 你可以在vm实例化之前设置data.attrs,
    // 这相当于在HTML标签中添加属性。

    // 你可以在children中追加vnode,
    // 这相当于在HTML标签内添加子元素。
  },
  created(ctx, vnode) {
    // do something

    // 此时vnode已创建,你访问修改vnode。
  },
})

app.$mount('#app')
  • local hook (sub component)
this.$vnhook.register({
  tag: 'el-column',
  beforeCreate(ctx, tag, data, children) {
    // do something

    // you can set data.attrs before the vm was instantiated,
    // this is equivalent to adding the attribute to the HTML tag.

    // You can append vnode in children,
    // this is equivalent to adding child elements inside HTML tags.
  },
  created(ctx, tag, vnode) {
    // do something

    // At this time, the vnode has been created, and you can access and modify the vnode.
  },
})

Licence

This repository is licensed under the Apache License 2.0 license.

Readme

Keywords

Package Sidebar

Install

npm i vue-vnode-hook

Weekly Downloads

0

Version

2.0.0

License

Apache-2.0

Unpacked Size

19.5 kB

Total Files

8

Last publish

Collaborators

  • mxstrive