【问题标题】:Get options of component by plugin通过插件获取组件的选项
【发布时间】:2016-11-22 14:26:52
【问题描述】:

在我的组件中我有这个选项(my_plugin)

<script>
  export default {
    ready () {
      // ...
    },
    my_plugin: 'test'
  }
</script>

在我的插件中,我需要获取 'my_plugin',我该怎么做?

export default function (Vue) {
    Vue.prototype.$plugin = (key) => {
        console.log(this.$options.my_plugin)
        return key
    }
}

【问题讨论】:

    标签: javascript vue-component vue.js


    【解决方案1】:

    如果您将组件设置为全局组件:

    Vue.component('your-component', {
        ready () {
          // ...
        },
        my_plugin: 'test'
    })
    

    然后你可以在 vue 实例上检索它:

    var YourComponent = Vue.component('your-component')
    

    并访问 my_plugin 参数:

    YourComponent.$options.my_plugin
    
    猜你喜欢
    • 2022-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-28
    • 2013-12-17
    • 1970-01-01
    • 2012-02-18
    • 2020-07-13
    相关资源
    最近更新 更多