移动开发vux组件

1)vux的组件的介绍

官网 vux是组件式开发其中有许多丰富的组件 以便web移动页面的快速开发

2)vux的使用步骤

2-1基于vux-cli webpack <projectName>创建的项目

  • 1 npm i vue-cli -g //安装vue脚手架
  • 2 vue init webpack <project> 创建项目
  • 3 npm install vux --save-dev 安装vux
  • 4 安装vux-loader (这个vux文档似乎没介绍,当初没安装结果报了一堆错误)
    npm install vux-loader --save-dev
  • 5 安装less-loader (这个是用以正确编译less源码,否则会出现 ' Cannot GET / ')
    npm install less less-loader --save-dev
  • 6 安装yaml-loader (以正确进行语言文件读取, 我没安装似乎也没报错)
    npm install yaml-loader --save-dev
  • 7(重要)
在build/webpack.base.conf.js 文件进行配置
const vuxLoader = require('vux-loader')
const webpackConfig = originalConfig

// 原来的 module.exports 代码赋值给变量 webpackConfig,

//即将原来的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')  
  
function resolve (dir) {  
  return path.join(__dirname, '..', dir)  
}  
const vuxLoader = require('vux-loader')  
const webpackConfig  = {  
  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: [  
      {  
        test: /\.vue$/,  
        loader: 'vue-loader',  
        options: vueLoaderConfig  
      },  
      {  
        test: /\.js$/,  
        loader: 'babel-loader',  
        include: [resolve('src'), resolve('test')]  
      },  
      {  
        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]')  
        }  
      }  
    ]  
  }  
}  
module.exports = vuxLoader.merge(webpackConfig, { plugins: ['vux-ui'] })  

题外话如果想要在vue脚手架创建的项目中使用ip或者域名访问(不是localhost)需要在config中的index.js中把host 改成0.0.0.0

3)布局

3-1 ViewBox 标准移动端页面布局
分为头部 内容和底部

头部使用组件XHeader
内容默认div 或者填充想要的其他组件
底部使用 Tabbar

整合新闻列表完整案例


image.png
//app.js
<template>
  <div id="app">
    <view-box>
      <x-header slot="header" class="v-header" :left-options="{showBack:false}"> <!--头部-->
        <div slot="left">首页</div>
        <div>我的新闻</div>
        <div slot="right">搜索</div>
      </x-header>
      <scroller :lock-y="true"> <!--滑动-->
        <div style="width:1000px;">
           <tab active-color='red' :line-width="1"> <!--导航-->
            <tab-item selected>推荐</tab-item>
            <tab-item>视频</tab-item>
            <tab-item>热点</tab-item>
            <tab-item>社会</tab-item>
            <tab-item>娱乐</tab-item>
            <tab-item>军事</tab-item>
            <tab-item>科技</tab-item>
            <tab-item>汽车</tab-item>
            <tab-item>体育</tab-item>
            <tab-item>财经</tab-item>
            <tab-item>国际</tab-item>
            <tab-item>时尚</tab-item>
          </tab>
        </div>
      </scroller>
      <swiper loop auto :list="loopData"><!--轮播-->

      </swiper>

      <panel :list="panelList"></panel>

      <tabbar slot="bottom"> <!--底部-->
        <tabbar-item>
          <span slot="label">我的</span>
        </tabbar-item>
        <tabbar-item>
          <span slot="label">关于</span>
        </tabbar-item>
      </tabbar>
    </view-box>
    <router-view/>
  </div>
</template>

<script>
import { ViewBox,XHeader,Tabbar,TabbarItem,Tab,TabItem,Scroller,Swiper,Panel } from 'vux';
const panelList = [];
for(let i =0;i<10;i++){
  panelList.push({
        src: 'http://somedomain.somdomain/x.jpg',
        fallbackSrc: 'http://placeholder.qiniudn.com/60x60/3cc51f/ffffff',
        title: '标题'+i,
        desc: '由各种物质组成的巨型球状天体,叫做星球。星球有一定的形状,有自己的运行轨道。',
        url: '/component/cell'
      })
}
export default {
  name: 'App',
  components:{
    ViewBox, //容器
    XHeader,  //头部
    Tabbar,  //底部
    TabbarItem, //底部列表
    Tab, //导航
    TabItem, //导航列表
    Scroller, //滑动效果
    Swiper, //轮播效果
    Panel  //新闻主体
  },
  data(){
    return {
      loopData: //轮播数据
        [{
          url: 'javascript:',
          img: 'https://static.vux.li/demo/1.jpg',
          title: '送你一朵fua'
        }, {
          url: 'javascript:',
          img: 'https://static.vux.li/demo/2.jpg',
          title: '送你一辆车'
        }, {
          url: 'javascript:',
          img: 'https://static.vux.li/demo/3.jpg',
          title: '送你一次旅行'
        }],
        panelList:panelList
    }
  }
}
</script>

<style lang="less">
@import '~vux/src/styles/reset.less';
html,body{
  height:100%;
  width:100%;
  overflow:hidden;
}
#app{
  height:100%;
  .v-header{
    background:red;
    div{
      color:#fff;
    }
  }
}
</style>

4)额外组件上拉刷新

vue-scroller
官网案例
https://wangdahoo.github.io/vue-scroller/#/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容