移動(dòng)開發(fā)vux組件

1)vux的組件的介紹

官網(wǎng) vux是組件式開發(fā)其中有許多豐富的組件 以便web移動(dòng)頁面的快速開發(fā)

2)vux的使用步驟

2-1基于vux-cli webpack <projectName>創(chuàng)建的項(xiàng)目

  • 1 npm i vue-cli -g //安裝vue腳手架
  • 2 vue init webpack <project> 創(chuàng)建項(xiàng)目
  • 3 npm install vux --save-dev 安裝vux
  • 4 安裝vux-loader (這個(gè)vux文檔似乎沒介紹,當(dāng)初沒安裝結(jié)果報(bào)了一堆錯(cuò)誤)
    npm install vux-loader --save-dev
  • 5 安裝less-loader (這個(gè)是用以正確編譯less源碼,否則會(huì)出現(xiàn) ' Cannot GET / ')
    npm install less less-loader --save-dev
  • 6 安裝yaml-loader (以正確進(jìn)行語言文件讀取, 我沒安裝似乎也沒報(bào)錯(cuò))
    npm install yaml-loader --save-dev
  • 7(重要)
在build/webpack.base.conf.js 文件進(jìn)行配置
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腳手架創(chuàng)建的項(xiàng)目中使用ip或者域名訪問(不是localhost)需要在config中的index.js中把host 改成0.0.0.0

3)布局

3-1 ViewBox 標(biāo)準(zhǔn)移動(dòng)端頁面布局
分為頭部 內(nèi)容和底部

頭部使用組件XHeader
內(nèi)容默認(rèn)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"> <!--滑動(dòng)-->
        <div style="width:1000px;">
           <tab active-color='red' :line-width="1"> <!--導(dǎo)航-->
            <tab-item selected>推薦</tab-item>
            <tab-item>視頻</tab-item>
            <tab-item>熱點(diǎn)</tab-item>
            <tab-item>社會(huì)</tab-item>
            <tab-item>娛樂</tab-item>
            <tab-item>軍事</tab-item>
            <tab-item>科技</tab-item>
            <tab-item>汽車</tab-item>
            <tab-item>體育</tab-item>
            <tab-item>財(cái)經(jīng)</tab-item>
            <tab-item>國際</tab-item>
            <tab-item>時(shí)尚</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">關(guān)于</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: '標(biāo)題'+i,
        desc: '由各種物質(zhì)組成的巨型球狀天體,叫做星球。星球有一定的形狀,有自己的運(yùn)行軌道。',
        url: '/component/cell'
      })
}
export default {
  name: 'App',
  components:{
    ViewBox, //容器
    XHeader,  //頭部
    Tabbar,  //底部
    TabbarItem, //底部列表
    Tab, //導(dǎo)航
    TabItem, //導(dǎo)航列表
    Scroller, //滑動(dòng)效果
    Swiper, //輪播效果
    Panel  //新聞主體
  },
  data(){
    return {
      loopData: //輪播數(shù)據(jù)
        [{
          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
官網(wǎng)案例
https://wangdahoo.github.io/vue-scroller/#/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容