Vue的组件化之notification组件/Vue.extend()

2020-03-11 21:22:36

参考地址 学习笔记——Vue的组件化之notification组件/Vue.extend()

学习笔记——Vue核心技术Vue+Vue-Router+Vuex+SSR实战精讲


一、把组件的内部结构写好,写成一个vue文件notification.vue。

二、全局设置组件属性。//如果后面不需要直接引入组件的方式调用,可以不用全局注册

index.js中一般写的是需要全局设置的属性。


import Notification from './notification.vue';


export default (Vue) => {

// 全局注册,在整个全局都可以使用这个component

    Vue.component(Notification.name, Notification);

}

1

2

3

4

5

6

调用

import Notification from './components/notification/index'

Vue.use(Notification); //因为export的是一个函数,所以需要用use调用

1

2

三、创建func-notification.js用于给组件添加属性,继承父类组件

四、创建function.js用于写方法,使得调用方法可以创建组件

1、通过var constructor = Vue.extend(func-notification)方法传入组件实例,可以通过new constructor()方法创建组件。

2、创建一个方法,用于创建组件与对组件的额外操作等。


const notify = (options) => {

    const instance = new NotificationConstructor({}); //instance是实例对象

}

1

2

3

3、传递属性。可直接设置propsData: options


五、把notify方法放到vue.prototype中,使得可以全局调用。

// index.js

    Vue.prototype.$notify = notify;

1

2

点赞



  • 2017-11-10 00:06:15

    CORS: credentials mode is 'include'

    XMLHttpRequest cannot load http://localhost/Foo.API/token. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:5000' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

  • 2017-11-19 00:17:51

    Java如何获取Date的“昨天”与“明天”示例代码

    最近在做项目的时候用到Date和Calendar比较多,而且用到的方式也比较全,突然想到一个问题,Java如何获取Date的"昨天"与"明天",也就是前一天和后一天呢?思考后写出了方法,想着万一以后用到,就总结出来,也方便有需要的朋友们参考借鉴,下面来一起看看吧。