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-02-13 17:50:05

    cURL error 60: SSL certificate problem: unable to get local issuer certificate

    Drupal 8 version uses Guzzle Http Client internally, but under the hood it may use cURL or PHP internals. If you installed PHP cURL on your PHP server it typically uses cURL and you may see an exception with error Peer certificate cannot be authenticated with known CA certificates or error code CURLE_SSL_CACERT (60).

  • 2017-02-16 08:09:01

    HTML中PRE和p的区别

    pre 元素可定义预格式化的文本。被包围在 pre 元素中的文本通常会保留空格和换行符。而文本也会呈现为等宽字体。 <pre> 标签的一个常见应用就是用来表示计算机的源代码。

  • 2017-02-16 15:14:14

    动态加载js和css

    开发过程中经常需要动态加载js和css,今天特意总结了一下常用的方法。