zoukankan      html  css  js  c++  java
  • vuerouter-9_ElementUI

     npm install element-ui -S

    完整应用:

    import Vue from 'vue';

    import ElementUI from 'element-ui';

    import 'element-ui/lib/theme-chalk/index.css';

    import App from './App.vue';

    Vue.use(ElementUI);

    new Vue({ el: '#app', render: h => h(App) });

    按需引入:

    借助 babel-plugin-component,我们可以只引入需要的组件,以达到减小项目体积的目的。

    首先,安装 babel-plugin-component:

    npm install babel-plugin-component -D
     .babelrc 修改为:

    {
    "presets": [
    ["env", {
    "modules": false,
    "targets": {
    "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
    }
    }],
    "stage-2"
    ],
    "plugins": ["transform-vue-jsx", "transform-runtime",[
    "component",
    {
    "libraryName": "element-ui",
    "styleLibraryName": "theme-chalk"
    }
    ]]
    }

    接下来,如果你只希望引入部分组件,比如 Button 和 Select,那么需要在 main.js 中写入以下内容:

    import Vue from 'vue';
    import { Button, Select } from 'element-ui';
    import App from './App.vue';
    
    Vue.component(Button.name, Button);
    Vue.component(Select.name, Select);
    /* 或写为
     * Vue.use(Button)
     * Vue.use(Select)
     */
    
    new Vue({
      el: '#app',
      render: h => h(App)
    });
    实例:

    <template>
    <div class="home">
    <ul class="ul-list">
    <router-link tag="li" to='/Home/Hot' >热门</router-link>
    <router-link tag="li" to='/Home/Recommend' >推荐</router-link>
    </ul>
    <router-view />
    home
    <el-row>
    <el-button>默认按钮</el-button>
    <el-button type="primary">主要按钮</el-button>
    <el-button type="success">成功按钮</el-button>
    <el-button type="info">信息按钮</el-button>
    <el-button type="warning">警告按钮</el-button>
    <el-button type="danger">危险按钮</el-button>
    </el-row>
    <Nav />
    </div>
    </template>

    <script>
    import Nav from '../Nav'
    export default{
    name:"Home",
    components:{Nav},
    data(){
    return{

    }
    }
    }
    </script>

    <style scoped>
    .ul-list{list-style:none;font-size:0;text-align:center;}
    .ul-list li{display:inline-block;font-size:14px;padding:5px;font-weight:bold;}
    .active{color:#42B983}
    </style>

     
  • 相关阅读:
    从远程仓库拉去的代码开发后用git推送到另外一个远程仓库
    Git回退本地和远程分支的的版本
    把win10本地hexo博客部署到腾讯云linux服务器
    linux安装mysql
    linux部署nginx
    apache服务器安装到linux
    SqlServerv报错:从数据类型 varchar 转换为 numeric 时出错。
    IDEA2020版Maven依赖成功导入但任然报错找不到包解决方案
    idea中左侧project栏自动隐藏如何解决
    拖延的坏处
  • 原文地址:https://www.cnblogs.com/xiao-peng-ji/p/11401621.html
Copyright © 2011-2022 走看看