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

点赞



  • 2018-02-23 14:22:50

    mysql的yearweek 和 weekofyear函数

    例如 2010-3-14 ,礼拜天 SELECT YEARWEEK('2010-3-14') 返回 11 SELECT YEARWEEK('2010-3-14',1) 返回 10 其中第二个参数是 mode ,具体指的意思如下: Mode First day of week Range Week 1 is the first week … 0 Sunday 0-53 with a Sunday in this year 1 Monday 0-53 with more than 3 days this year 2 Sunday 1-53 with a Sunday in this year 3 Monday 1-53 with more than 3 days this year 4 Sunday 0-53 with more than 3 days this year 5 Monday 0-53 with a Monday in this year 6 Sunday 1-53 with more than 3 days this year 7 Monday 1-53 with a Monday in this year 2.

  • 2018-02-23 17:20:44

    Mysql数据库If语句的使用

    MySQL的if既可以作为表达式用,也可在存储过程中作为流程控制语句使用,如下是做为表达式使用:

  • 2018-02-24 10:16:36

    Java工具类之Apache的Commons Lang和BeanUtils

    Apache Commons包估计是Java中使用最广发的工具包了,很多框架都依赖于这组工具包中的一部分,它提供了我们常用的一些编程需要,但是JDK没能提供的机能,最大化的减少重复代码的编写。