Code Monkey home page Code Monkey logo

custom-global-component's Introduction

custom-global-component

vue2 自定义全局组件,以loading加载效果为例

Build Setup

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build

构建项目

vue init webpack-simple custom-global-component
cnpm install
npm run dev
  1. 自定义vue组件,首先要创建组件文件,在loading文件夹中Loading.vue直接按照vue template相关规则写即可

image

  1. 创建Loading.vue组件之后,要建立相关的js调用这个Loading.vue,进行相关配置后导出使用。index.js中中间部分配置最为重要,
主要文件index.js代码:

    import LoadingComponent from './Loading.vue'
    const Loading={
        install: function(Vue){
            Vue.component('Loading',LoadingComponent)
        }
    }
    export default Loading

说明:Vue.component('Loading',LoadingComponent);中的'Loading',
这个命名就是在其他文件中调用这个组件的名字,例如调用这个loading可以写成<Loading></Loading>

image

3.使用这个组件

image

image

custom-global-component's People

Contributors

ccyinghua avatar

Stargazers

Seeker avatar

Watchers

James Cloos avatar

Forkers

libin1991 dsnzts

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.