初识vue(6)—— Mint UI 的 完全引入 和 按需引入

Mint UI 是基于 Vue.js 的移动端组件库,包含丰富的 CSS 和 JS 组件,能够满足日常的移动端开发需要。
关于如何安装 vue 脚手架项目,请看我的博客 初识vue(2)——如何搭建脚手架项目
先安装 Mint UI
npm install --save mint-ui
一、完全引入

在 main.js 文件中写:

import Vue from 'vue'
import MintUI from 'mint-ui'
import 'mint-ui/lib/style.css'
import App from './App.vue'

Vue.use(MintUI)

new Vue({
  el: '#app',
  components:{
    App
  },
  template:'<App/>'
})

在 App.vue 中写:

<template>
  <div>
    <mt-button type="default" size="large">default</mt-button>
    <mt-button type="primary" size="large">primary</mt-button>
    <mt-button type="danger" size="large">danger</mt-button>
  </div>
</template>

<script>
export default {
  
}
</script>

<style>

</style>

运行效果如下图所示:
在这里插入图片描述

二、按需引入
1. 安装 babel-plugin-component:
npm install --save-dev babel-plugin-component
2. 将 .babelrc 文件中的 plugins 修改为:
"plugins": ["transform-vue-jsx", "transform-runtime",["component", [
    {
      "libraryName": "mint-ui",
      "style": true
    }
  ]]]
3. 在 main.js 文件中写:
import Vue from 'vue'
import { Button} from 'mint-ui'
import App from './App.vue'

Vue.component(Button.name, Button)
/* 或写为
 * Vue.use(Button)
 */

new Vue({
  el: '#app',
  components:{
    App
  },
  template:'<App/>'
})
4. 在 App.vue 中写:
<template>
  <div>
    <mt-button type="primary" size="large" @click.native="handleClick">primary</mt-button>
  </div>
</template>

<script>
import { Toast } from 'mint-ui'
export default {
  methods:{
    handleClick(){
      Toast('提示信息')
    }
  }
}
</script>

<style>

</style>
5. 运行结果如下图所示:

在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值