• mintUI配合vue2.0,webpack,vue-cli脚手架从零搭建


    虽然vue-cli脚手架很方便,但是有些配置还是不够,

    所以个人配置了一个mintUI的移动端单页面模板,可以使用less,axios,mintUI等常用组件和loading.

    还配置了一个elementUI的pc端单页面模板。

    代码地址:https://gitee.com/LIULIULIU8/elementui_mintui__template_file

      运行说明:

        1、进入到文件夹,输入命令行:cnpm install  初始化下载

        2、运行 cnpm run dev  ;即可打开访问

    好用给个star哦!!

    步骤说明:

    
    
    
    

    1.确保安装了vue-cli
    安装:cnpm install vue-cli -g
    验证版本:vue --version

    
    

    2.生成项目模板:
    vue init webpack-simple mintui-case-wxactivity

    
    

    3.进入项目目录
    初始化:cnpm install
    运行:cnpm run dev

    
    

    4.下载引入vueRouter,并使用
    下载:cnpm install vue-router --save-dev
    引入:import VueRouter from 'vue-router'
    注册:Vue.use(VueRouter);
    配置路径:
    const routes = [
    {path:'/',component:home}
    ];

    
    

    const router = new VueRouter({
    // linkActivity:'active',
    routes:routes
    })

    
    

    5.初始化Vue
    new Vue({
    router:router,
    el: '#app',
    render: h => h(App)
    })

    
    

    6.安装使用mintUI
    安装:cnpm install mint-ui -save
    引入使用:
    //引入全部组件
    import Mint from 'mint-ui'
    import 'mint-ui/lib/style.css' //注意,此处样式要单独引入。
    Vue.use(Mint);
    //按需引入部分组件
    import {Button} from 'mint-ui'
    import 'mint-ui/lib/button/style.css'
    Vue.component(Button.name,Button);

    7.下载并使用less
    安装:$ cnpm install less less-loader --save
    配置webpack.config
    {
    test:/.less$/,
    loader:'style-loader!css-loader!less-loader'
    },

    
    

    8.下载并使用axios
    安装:cnpm install axios --save
    配置:在api文件中
    使用:在某组件中,按需引入需要的接口请求 例:import {requestLogin} from '../api/'

    main.js:

    import Vue from 'vue'
    import App from './App.vue'
    import VueRouter from 'vue-router'
    
    //引入全部组件
        // import Mint from 'mint-ui'
        // import 'mint-ui/lib/style.css'
    //按需引入部分组件
    import {Button} from 'mint-ui'
    import 'mint-ui/lib/button/style.css'
    Vue.component(Button.name,Button);
    
    
    
    // 引入组件
    import home from './components/Home.vue'
    //注册
    Vue.use(VueRouter);
    
    
    const routes = [
      {path:'/',component:home}
    ];
    
    const router = new VueRouter({
      // linkActivity:'active',
      routes:routes
    })
    
    
    
    
    new Vue({
      router:router,
      el: '#app',
      render: h => h(App)
    })

    webpack.config.js

    var path = require('path')
    var webpack = require('webpack')
    
    module.exports = {
      entry: './src/main.js',
      output: {
        path: path.resolve(__dirname, './dist'),
        publicPath: '/dist/',
        filename: 'build.js'
      },
      module: {
        rules: [
          {
            test: /.css$/,
            use: [
              'vue-style-loader',
              'css-loader'
            ],
          },      {
            test: /.vue$/,
            loader: 'vue-loader',
            options: {
              loaders: {
              }
              // other vue-loader options go here
            }
          },
          {
            test: /.js$/,
            loader: 'babel-loader',
            exclude: /node_modules/
          },
          {
            test:/.less$/,
            loader:'style-loader!css-loader!less-loader'
          },
          {
            test: /.(png|jpg|gif|svg)$/,
            loader: 'file-loader',
            options: {
              name: '[name].[ext]?[hash]'
            }
          }
        ]
      },
      resolve: {
        alias: {
          'vue$': 'vue/dist/vue.esm.js'
        },
        extensions: ['*', '.js', '.vue', '.json']
      },
      devServer: {
        historyApiFallback: true,
        noInfo: true,
        overlay: true
      },
      performance: {
        hints: false
      },
      devtool: '#eval-source-map'      //开发模式时打开
    }
    
    if (process.env.NODE_ENV === 'production') {
      module.exports.devtool = '#source-map'
      // http://vue-loader.vuejs.org/en/workflow/production.html
      module.exports.plugins = (module.exports.plugins || []).concat([
        new webpack.DefinePlugin({
          'process.env': {
            NODE_ENV: '"production"'
          }
        }),
        new webpack.optimize.UglifyJsPlugin({
          sourceMap: true,
          compress: {
            warnings: false
          }
        }),
        new webpack.LoaderOptionsPlugin({
          minimize: true
        })
      ])
    }
  • 相关阅读:
    linux之dup和dup2函数解析
    UNIX标准及实现
    UNIX基础知识
    HTML5学习笔记----html5与传统html区别
    c#设计模式-简单工厂
    c#设计模式-工厂模式
    MVC模式与三层架构的区别
    C# params传递多个参数
    SFC20 功能例子 注解
    工业以太网:十个核心基础概念
  • 原文地址:https://www.cnblogs.com/LChenglong/p/8033694.html
Copyright © 2020-2023  润新知