vux是能夠連繫vue運用的一個微信端組件庫,我平常用它來做簡樸的提醒框、loading動畫、confirm之類的功用。vux內里有許多很有用的功用,細緻的能夠去看官方文檔。
我主要就紀錄一下vux的裝置和也許運用要領。
裝置:
//裝置vux
npm install vux --save
//vux是基於vux-loader的,所以必須要裝置這個,不然會報一大堆錯
npm install vux-loader --save-dev
//裝置less,vux運用的是less
npm install less less-loader --save-dev
//這個我看他人的教程內里裝了,我沒裝,也沒報錯,先紀錄在這裏,假如今後報錯的話能夠把這個裝置上嘗嘗
npm install yaml-loader --save-dev
一切的裝置完成以後,須要舉行一波設置:
在 build/webpack.base.conf.js 中:
//官網上是如許寫的
const vuxLoader = require('vux-loader')
const webpackConfig = originalConfig
// 本來的 module.exports 代碼賦值給變量 webpackConfig
module.exports = vuxLoader.merge(webpackConfig, {
plugins: ['vux-ui']
})
詳細的實例代碼以下:
const vuxLoader = require('vux-loader');
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'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
}
},
module: {
rules: [
{
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: /\.scss$/,
include:'/src/',
loader: 'style-loader!css-loader!sass-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']
})
在 main.js 中
參考官網供應的要領引入你所須要的組件,就能夠愉快地運用它啦!
//我平常是用plugin的體式格局引入,先引入,再use
import {AlertPlugin,LoadingPlugin,ConfirmPlugin,ToastPlugin} from 'vux';
Vue.use(AlertPlugin);
Vue.use(LoadingPlugin);
Vue.use(ConfirmPlugin);
Vue.use(ToastPlugin);
接下來在html代碼中運用:
this.$vux.alert.show({
title: "提醒",
content: "哈哈哈"
})
注重:運用的要領能夠參考官方文檔,寫的很清晰。在運用過程中沒什麼坑,裝置的時刻坑比較多。假如報錯了,就看一下報錯信息是否是提醒有什麼該裝的東西沒裝,再裝置一下就能夠了。