Vue系列之 => MintUI初使用

安装 css

npm i mint-ui -S vue

main.jsvue-router

import Vue from 'vue'
// 1,导入 vue-router包
import vueRouter from 'vue-router'
// 导入mintui
import MintUI from 'mint-ui'
import 'mint-ui/lib/style.css'
// 使用bootstrap的样式
import 'bootstrap/dist/css/bootstrap.css'
import './css/app.css'
// 导入app组件
import app from './app.vue'
import router from './router.js'

// 将MintUI 安装到Vue
Vue.use(MintUI);
// 2,手动安装vueRouter
Vue.use(vueRouter);

var vm = new Vue({
    el: '#app',
    render: c => c(app), // render会把el 指定的容器中全部的内容都清空覆盖
    // 因此不要把router-view和router-link直接写到 el 所控制的元素中。
    router
})
// 注意app这个组件是经过vm实例的render函数渲染的,render函数若是要渲染组件
// 渲染出来的组件只能放到el : '#app' 所指定的元素中去。
// account 和 goodslist组件是经过路由匹配监听到的,因此,这两个组件只能展现到
// 属于路由的<router-view></router-view>中去。

app.vuenpm

<template>
  <div>
    <h1>app组件</h1>
    <mt-button type="primary" icon="more" @click="show">默认按钮</mt-button>
    <router-link to="/account">account</router-link>
    <router-link to="/goodslist">goodslist</router-link>
    <router-view></router-view>
  </div>
</template>

<script>
import { Toast } from "mint-ui";

export default {
  data() {
    return {
        toastInstanse : null
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      //模拟获取数据的方法
      this.show();
      setTimeout( () => {
        //   当5S事后,数据获取成功后要把Toast移除
        this.toastInstanse.close();
      }, 5000);
    },
    show() {
      this.toastInstanse = Toast({
        message: "提示消息",
        // duration : -1, //若是是-1则弹出后不消失
        duration: -1,
        iconClass: "glyphicon glyphicon-heart",
        className: "mytoast"
      });
    }
  }
};
</script>

<style lang="">
</style>

app.cssbootstrap

.mytoast i{
    color : red !important;
}

 按需导入模块以减小文件大小,安装 babel-plugin-componentbabel

cnpm i babel-plugin-component -Dapp

而后修改.babelrc文件函数

{
    "presets": ["env", "stage-0"],
    "plugins": ["transform-runtime", ["component", [{
        "libraryName": "mint-ui",
        "style": true
    }]]]
}

而后再引入单个模块后,用vue组件注册ui

import { Button,Cell } from 'mint-ui'

// 使用vue.component 注册按钮组件
Vue.component('mybtn',Button);  //组件名称,实例名称
相关文章
相关标签/搜索