vux是一款基于Vue构建的移动UI组件库(https://doc.vux.li/zh-CN/)
1.使用npm安装vuxnpm install vux --save
2.安装vux-loader(vux2必须配合vux-loader使用)npm install vux-loader --save-dev
3.安装less-loader(用以正确编译less源码,否则会出现 ' Cannot GET / ')npm install less less-loader --save-dev
4.安装yaml-loader (以正确进行语言文件读取)npm install yaml-loader --save-dev
"devDependencies": {
...
"less-loader": "^5.0.0",
"yaml-loader": "^0.5.0"
...
}
5.在build/webpack.base.conf.js 文件进行配置
const vuxLoader = require('vux-loader')
//将module.exports代码赋值给变量const webpackConfig
module.exports = vuxLoader.merge(webpackConfig, { plugins: ['vux-ui'] })
在resolve: {
extensions: ['.js', '.vue', '.json', 'less'],
...
},里加入.less
完整的webpack.base.conf.js内容:
'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')
const vuxLoader = require('vux-loader')
function resolve (dir) {
return path.join(__dirname, '..', dir)
}
const createLintingRule = () => ({
// test: /\.(js|vue)$/,
// loader: 'eslint-loader',
// enforce: 'pre',
// include: [resolve('src'), resolve('test')],
// options: {
// formatter: require('eslint-friendly-formatter'),
// emitWarning: !config.dev.showEslintErrorsInOverlay
// }
})
const webpackConfig = {
context: path.resolve(__dirname, '../'),
entry: {
app: './src/main.js'
},
output: {
path: config.build.assetsRoot,
filename: '[name].js',
publicPath: process.env.NODE_ENV === 'production'
? config.build.assetsPublicPath
: config.dev.assetsPublicPath
},
resolve: {
extensions: ['.js', '.vue', '.json', 'less'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
}
},
module: {
rules: [
...(config.dev.useEslint ? [createLintingRule()] : []),
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
},
{
test: /\.less$/,
loader: "style-loader!css-loader!less-loader",
}
]
},
node: {
// prevent webpack from injecting useless setImmediate polyfill because Vue
// source contains it (although only uses it if it's native).
setImmediate: false,
// prevent webpack from injecting mocks to Node native modules
// that does not make sense for the client
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
}
}
module.exports = vuxLoader.merge(webpackConfig, {plugins: ['vux-ui']})
6.main.js中添加全局引用
import {ToastPlugin,LoadingPlugin} from 'vux'
Vue.use(ToastPlugin)
Vue.use(LoadingPlugin)
组件中局部引用
<script>
export default {
import {Datetime} from 'vux'
components: {
Datetime
}
}
</script>
<template>
<datetime format="YYYY-MM-DD" v-model="month" class="date-time" :end-date="date"
@on-confirm="queryMonthLend"></datetime>
</template>
7.index.vue中使用
<script>
created() {
this.$vux.loading.show({
"text": "加载中..."
})
},
</script>
若在安装过程中报错:
*!!vue-style-loader!css-loader?{"sourceMap":true}!../../../../vue-loader
可参考https://blog.csdn.net/genius_...
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。