Vue组件无法呈现vue-notify

时间:2017-11-18 06:12:24

标签: javascript vue.js vuejs2 vue-component

我正在使用此库:https://github.com/cristijora/vue-notifyjs

上面的文档说明:component: { //is rendered instead of notification message因此我试图给它动态组件,以便我可以处理自定义事件。这是我的代码:

Vue.use(vueNotifyjs)
new Vue({
  el: '#app',

  methods: {
    addNotification(verticalAlign = 'top', horizontalAlign = 'right') {
      this.$notify({
        component: function(){
            return {
            template: '<h1>Hello</h1>'
           };
        },
        horizontalAlign: horizontalAlign,
        verticalAlign: verticalAlign,
        type: "success"
      })
    }
  }
})

这是我的jsfiddle:https://jsfiddle.net/z11fe07p/2706/

但是Hello这个词没有在通知中呈现。有什么想法我错过了吗?

1 个答案:

答案 0 :(得分:1)

我认为组件键应该有一个Vue组件的实例。 在您的方案中,按如下所示创建vue组件

Vue.component('custom-message',{ template:`<div>Hello World</div>` })

我在这个link中修改了上面的小提琴。

希望有所帮助

相关问题