美文网首页
vue use install

vue use install

作者: 黄黄黄大帅 | 来源:发表于2020-10-28 08:10 被阅读0次

相信很多人在用Vue使用别人的组件时,会用到 Vue.use() 。例如:Vue.use(VueRouter)、Vue.use(MintUI)。但是用 axios时,就不需要用 Vue.use(axios),就能直接使用。那这是为什么呐?因为 axios 没有 定义install方法,Vue.use(XX)方法是专门用来执行作为参数的XX组件里面定义的 install方法,如果该组件没有install方法,则Vue.use失效。


image.png
  • mycomponent.vue
<template>
  <div>mycomponent</div>
</template>
<script>
export default {}
</script>

<style></style>
  • mycomponent.js 声明mycomponent 对象,赋予install方法,注册全局组件
import component from "./mycomponent.vue"
const mycomponent = {
  install: function(Vue,options) {
    Vue.component("mycomponent", component)
  },
}
export default mycomponent
  • main.js或其他js调用(我这里是print.js调用),Vue.use方法是执行作为参数的vue组件mycomponent1里面定义的 install方法
import Vue from "vue"
import mycomponent1 from "./mycomponent.js"
Vue.use(mycomponent1)

其实与vue自定义组件是一样的,只不过自定义组件多了一对函数,即:Vue.use()和install

相关文章

  • vue use install

    相信很多人在用Vue使用别人的组件时,会用到 Vue.use() 。例如:Vue.use(VueRouter)、V...

  • vue路由配置

    1.安装 npm install vue-router --save 2. 引入并 Vue.use(VueRout...

  • Vue插件原理概述

    Vue 插件实现原理: Obj = 插件对象 Vue.use(obj) Obj必须有一个install方法,该方法...

  • Vue.js总结学习

    1、Vue.use() vue官网有给出明确的文档vue插件开发,我们需要有一个公开方法install,里面来包含...

  • 为什么axios、echart不需要Vue.use()

    因为 axios、echart 没有 install方法 Vue.use()先判断是否注册过这个插件,然后看插件中...

  • Vue.use() 注册插件(个人笔记)

    Vue.use是什么? 官方对 Vue.use() 方法的说明:通过全局方法 Vue.use() 使用插件,Vue...

  • Vue注册组件

    task 把写在components/common下面的组件, 通过install和Vue.use的方法统一管理,...

  • Vue.use, Vue.component,router-vi

    ? Vue.use Vue.use 的作用是安装插件 Vue.use 接收一个参数 如果这个参数是函数的话,Vue...

  • python call linux cmd

    history old version use now use subprocess32 install use

  • Vue.use源码

    官方对 Vue.use() 方法的说明: 通过全局方法 Vue.use() 使用插件;Vue.use 会自动阻止多...

网友评论

      本文标题:vue use install

      本文链接:https://www.haomeiwen.com/subject/lfbxvktx.html