Iconfont-阿里巴巴矢量图标库:https://www.iconfont.cn
这里有个坑就是:微信不支持本地字体图标
从 阿里巴巴矢量图标库 下载到本地的,但是uni-app不支持本地iconfont.css,报错
00:42:22.580 Module build failed: ModuleNotFoundError: Module not found: Error: Can't resolve './iconfont.eot?t=1521557349802' in 'D:\workspace\appProjects\uniQingchi\pages\index'
00:42:22.592 at factoryCallback (D:\app\HBuilderX\plugins\uniapp\node_modules\webpack\lib\Compilation.js:264:39)
00:42:22.592 at factory (D:\app\HBuilderX\plugins\uniapp\node_modules\webpack\lib\NormalModuleFactory.js:247:20)
00:42:22.603 at resolver (D:\app\HBuilderX\plugins\uniapp\node_modules\webpack\lib\NormalModuleFactory.js:65:21)
00:42:22.613 at asyncLib.parallel (D:\app\HBuilderX\plugins\uniapp\node_modules\webpack\lib\NormalModuleFactory.js:138:21)
解决方案:从阿里巴巴矢量图标库 获取在线连接
@import "./styles/iconfont.wxss";
<text class="iconfont">text>
https://uniapp.dcloud.io/component/README?id=uniui
uni-ui 是 DCloud 提供的一个跨端 ui 库,它是基于vue组件的,flex布局的,无dom 的跨全端 ui 框架
uni-ui 不包括基础组件,它是基础组件的补充
数字角标,日历,卡片,折叠面板,倒计时,抽屉,悬浮按钮,收藏按钮,底部购物导航,宫格,图标,索引列表,加载更多,自定义导航栏,通告栏,数字输入框,分页器,弹出层,评分,搜索栏,分段器,步骤条,滑动操作,轮播图指示点,标签
npm install @dcloudio/uni-ui
在 script 中引用组件:
import {uniBadge} from '@dcloudio/uni-ui'
//import uniBadge from '@dcloudio/uni-ui/lib/uni-badge/uni-badge.vue' //也可使用此方式引入组件
export default {
components: {uniBadge}
}
在 template 中使用组件:
<uni-badge text="1">uni-badge>
<uni-badge text="2" type="success" @click="bindClick">uni-badge>
<uni-badge text="3" type="primary" :inverted="true">uni-badge>
更多
onLoad() {
//http://157.122.54.189:9088/image/v3/homepage/vertical
// 1 原生的微信小程序的 api
wx.request({
url:"http://157.122.54.189:9088/image/v3/homepage/vertical",
success:(res) =>{
console.log(res)
}
})
//2. uni-api
uni.request({
url:"http://157.122.54.189:9088/image/v3/homepage/vertical",
}).then(res => {
console.log(res)
})
},
分段器·指的是 uni-ui 中的一个组件,其实就是我们俗称的 标签页,tab页
https://ext.dcloud.net.cn/plugin?id=54
<template>
<view class="content">
<view>
<uni-segmented-control
:current="current"
:values="items.map(a=>a.title)"
@clickItem="onClickItem"
style-type="text"
active-color="#d4237a">
uni-segmented-control>
<view class="content">
<view v-if="current === 0">
<home-recommend>home-recommend>
view>
<view v-if="current === 1">
<home-category>home-category>
view>
<view v-if="current === 2">
<home-new>home-new>
view>
<view v-if="current === 3">
<home-album>home-album>
view>
view>
view>
view>
template>
<script>
import homeRecommend from './home-recommend';
import homeCategory from './home-category';
import homeNew from './home-new';
import homeAlbum from './home-album';
import { uniSegmentedControl } from "@dcloudio/uni-ui";
export default {
data (){
return {
items: [{
title:'推荐'
},
{
title:'分类'
},
{
title:'最新'
},
{
title:'专辑'
}],
current: 0
}
},
components: {
homeRecommend,
homeCategory,
homeNew,
homeAlbum,
uniSegmentedControl
},
methods: {
onClickItem(index) {
if (this.current !== index.currentIndex) {
this.current = index.currentIndex;
}
}
}
}
script>
<style>
style>
<view>
<view class="上 home_tab">
<view >
1(这个一般不写)
view>
<view class="home_tab_title">
2(分段器)
view>
<view class="search_icon">
3(搜索按钮)
<text class="iconfont">text>
view>
view>
<view class="下 content">
4(内容)
view>
view>
<style lang="scss">
.home_tab{
position: relative;
.home_tab_title{
width: 60%;
margin: 0 auto;
}
.search_icon{
position: absolute;
top: 50%;
transform: translateY(-50%);
right: 5%;
}
}
style>
// es6
export default (params)=>{
//加载中
uni.showLoading({
title:"加载中"
})
return new Promise((resolve,reject)=>{
wx.request({
...params,
success:(res)=>{
resolve(res.data)
},
fail:(err)=>{
reject(err)
},
complete() {
uni.hideLoading();
}
})
})
}
在 main.js 中
import request from "./utils/request.js"
Vue.prototype.request=request;
onLoad(){
this.request({
url:"http://157.122.54.189:9088/image/v3/homepage/vertical"
}).then(res=>{
console.log(res);
})
}
接口文档
https://www.showdoc.cc/414855720281749?page_id=3618621017219602
数据动态渲染
moment.js 的使用(时间格式)
momentjs.cn
npm install moment --save # npm
yarn add moment # Yarn
Install-Package Moment.js # NuGet
spm install moment --save # spm
meteor add momentjs:moment # meteor
bower install moment --save # bower (废弃)
<script>
import moment from "moment";
this.monthes.MM = moment(this.monthes.stime).format("MM");
this.monthes.DD = moment(this.monthes.stime).format("DD");
</script>
解决办法:
加个判断
<template>
<view v-if="recommends.length>0">
<template>
<scroll-view class="recommend_view"
@scrolltolower="handerToLower"
scroll-y v-if="recommends.length>0">
<script>
methods:{
//滚动条触底事件
handerToLower(){
console.log("迟到大王大大");
}
}
<style lang="scss">
.recommend_view{
//height: 屏幕的高度 - 头部标题的高度
height: calc( 100vh - 36px);
首页-推荐 页面:
<template>
<scroll-view class="recommend_view" @scrolltolower="handerToLower"
scroll-y v-if="recommends.length>0">
<view class="recommend_warp">
<view class="recommend_item" v-for="item in recommends"
:key="item.id">
<image mode="widthFix" :src="item.thumb">image>
view>
view>
<view class="monthes_warp">
<view class="monthes_title">
<view class="monthes_title_info">
<view class="monthes_info">
<text> {{monthes.DD}} /text>
{{monthes.MM}} 月
view>
<view class="monthes_text">
{{monthes.title}}
view>
view>
<view class="monthes_title_more">
更多 >
view>
view>
<view class="monthes_content">
<view class="monthes_item" v-for="item in monthes.items" :key="item.id">
<image mode="widthFix"
:src="item.thumb+item.rule.replace('$',360)" >
image>
view>
view>
view>
<view class="hots_wrap">
<view class="hots_title">
<text>热门text>
view>
<view class="hots_content">
<view class="hots_item" v-for="item in hots" :key="item.id">
<image mode="widthFix" :src="item.thumb">
image>
view>
view>
view>
scroll-view>
template>
<script>
import moment from "moment";
export default {
data(){
return{
//推荐列表
recommends:[],
//月份
monthes:{},
//热门
hots:[],
//请求的参数
params:{
//要获取几条
limit: 30,
//关键字
order: 'hot',
//要跳过几条
skip: 0
},
//是否还有下一页
hasMore:true
}
},
mounted() {
this.getList();
},
methods:{
//获取接口的数据
getList(){
this.request({
url: 'http://157.122.54.189:9088/image/v3/homepage/vertical',
data: this.params
}).then(result =>{
// 判断有没有下一页数据
if(result.res.vertical.length===0){
this.hasMore=false;
return;
}
if(this.recommends.length===0){
//第一次发送的请求
//推荐模块
this.recommends = result.res.homepage[1].items;
//月份模块
this.monthes = result.res.homepage[2];
//将时间戳 改成 18号/月 moment.js
this.monthes.MM = moment(this.monthes.stime).format("MM");
this.monthes.DD = moment(this.monthes.stime).format("DD");
}
//获取热门数据的列表
// 数组拼接 es6
//this.hots = result.res.vertical;
this.hots = [...this.hots, ...result.res.vertical];
})
},
//滚动条触底事件
handerToLower(){
/**
* 1. 修改参数 skip+=limit;
* 2. 重新发送请求 getList()
* 3. 请求回来成功 hots 数据的叠加
*/
if(this.hasMore){
this.params.skip += this.params.limit;
this.getList();
}else{
// 弹窗提示用户
uni.showToast({
title:"没有了哟",
icon:"none"
})
}
}
}
}
script>
<style lang="scss">
.recommend_view{
//height: 屏幕的高度 - 头部标题的高度
height: calc( 100vh - 36px);
}
.recommend_warp{
display: flex;
flex-wrap: wrap;
.recommend_item{
width: 50%;
border: 5rpx solid #000;
}
}
.monthes_warp{
.monthes_title{
display: flex;
justify-content: space-between;
padding: 20rpx;
.monthes_title_info{
color: $color;
font-size: 30rpx;
font-weight: 600;
display: flex;
.monthes_info{
text{
font-size: 36rpx;
}
}
.monthes_text{
font-size: 34rpx;
color: #666;
margin-left: 30rpx;
}
}
.monthes_title_more{
font-size: 24rpx;
color: $color;
}
}
.monthes_content{
display: flex;
flex-wrap: wrap;
.monthes_item{
width: 33.3%;
border: 5rpx solid #fff;
}
}
}
.hots_wrap{
.hots_title{
padding: 20rpx;
text{
border-left: 20rpx solid $color;
padding-left: 20;
font-size: 34rpx;
font-weight: 600;
}
}
.hots_content{
display: flex;
flex-wrap: wrap;
.hots_item{
width: 33.3%;
border: 5rpx solid #fff;
image{
}
}
}
}
style>