<template>
<gracePage :customHeader="false">
<view class="grace-body" slot="gBody">
<view class="grace-margin-top">
<text class="grace-title">横向滚动</text>
</view>
<graceSpeaker :vertical="false" :interval="5000" @change="change"
iconClass="grace-icons icon-gonggao" :msgs="speakerMsgs"></graceSpeaker>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/components/gracePage.vue";
import graceSpeaker from "../../graceUI/components/graceSpeaker.vue";
export default{
data() {
return {
speakerMsgs : []
/* 组件需要的格式
speakerMsgs : [
{ title: "GraceUI 更快、更好的前端UI", url:"../index/index", opentype: "navigate"},
{ title: "Hcoder.net - 精品 IT 课程中心", url: "../index/index", opentype: "switchTab"}
]*/
}
},
onLoad:function(){
// api 返回的数据格式与组件格式不匹配, 如:
// 模拟 api 请求
setTimeout(()=>{
// 假设 api 返回下面格式的数据
var data = [
{ txt: "GraceUI 更快、更好的前端UI", path:"../index/index", type: "navigate"},
{ txt: "Hcoder.net - 精品 IT 课程中心", path: "../index/index", type: "switchTab"}
];
// 其中 title 与 txt, path 与 url, type 与 opentype 不匹配
// 解决方案
// 01. 后台输出符合 组件要求的 api 数据
// 02. 前端转换, 范例代码 :
var newData = [];
// 遍历数据 转换对象格式
data.forEach((item)=>{
item.title = item.txt;
item.url = item.path;
item.opentype = item.type;
newData.push(item);
})
// 转换后将数据赋值到组件
this.speakerMsgs = newData;
})
},
components:{
gracePage, graceSpeaker
},
methods:{
change : function (index) {
console.log('切换到第 ' + index + ' 个项目');
}
}
}
</script>
<style>
</style>
<template>
<gracePage :customHeader="false">
<view class="grace-body" slot="gBody">
<view class="grace-margin-top">
<text class="grace-title">横向滚动</text>
</view>
<graceSpeaker :vertical="false" @change="change" iconClass="grace-icons icon-gonggao" :msgs="speakerMsgs">
<text class="grace-icons grace-blue"></text>
</graceSpeaker>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/weexComponents/gracePage.nvue";
import graceSpeaker from "../../graceUI/weexComponents/graceSpeaker.nvue";
export default{
data() {
return {
speakerMsgs : []
/* 组件需要的格式
speakerMsgs : [
{ title: "GraceUI 更快、更好的前端UI", url:"../index/index", opentype: "navigate"},
{ title: "Hcoder.net - 精品 IT 课程中心", url: "../index/index", opentype: "switchTab"}
]*/
}
},
onLoad:function(){
// api 返回的数据格式与组件格式不匹配, 如:
// 模拟 api 请求
setTimeout(()=>{
// 假设 api 返回下面格式的数据
var data = [
{ txt: "GraceUI 更快、更好的前端UI", path:"../index/index", type: "navigate"},
{ txt: "Hcoder.net - 精品 IT 课程中心", path: "../index/index", type: "switchTab"}
];
// 其中 title 与 txt, path 与 url, type 与 opentype 不匹配
// 解决方案
// 01. 后台输出符合 组件要求的 api 数据
// 02. 前端转换, 范例代码 :
var newData = [];
// 遍历数据 转换对象格式
data.forEach((item)=>{
item.title = item.txt;
item.url = item.path;
item.opentype = item.type;
newData.push(item);
})
// 转换后将数据赋值到组件
this.speakerMsgs = newData;
})
},
components:{
gracePage, graceSpeaker
},
methods:{
change : function (index) {
console.log('切换到第 ' + index + ' 个项目');
}
}
}
</script>
<style>
.grace-icons{font-size:28rpx;}
</style>
.wxml
<gracePage customHeader="{{false}}">
<view class="grace-body" slot="gBody">
<view class="grace-margin-top">
<text class="grace-title">横向滚动</text>
</view>
<grace-speaker vertical="{{false}}" bind:change="change"
interval="{{5000}}" iconClass="grace-icons icon-gonggao" msgs="{{speakerMsgs}}"></grace-speaker>
</view>
</gracePage>.js
Page({
data: {
speakerMsgs : []
/* 组件需要的格式
speakerMsgs : [
{ title: "GraceUI 更快、更好的前端UI", url:"../index/index", opentype: "navigate"},
{ title: "Hcoder.net - 精品 IT 课程中心", url: "../index/index", opentype: "switchTab"}
]*/
},
onLoad:function(){
// api 返回的数据格式与组件格式不匹配, 如:
// 模拟 api 请求
setTimeout(()=>{
// 假设 api 返回下面格式的数据
var data = [
{ txt: "GraceUI 更快、更好的前端UI", path:"../index/index", type: "navigate"},
{ txt: "Hcoder.net - 精品 IT 课程中心", path: "../index/index", type: "switchTab"}
];
// 其中 title 与 txt, path 与 url, type 与 opentype 不匹配
// 解决方案
// 01. 后台输出符合 组件要求的 api 数据
// 02. 前端转换, 范例代码 :
var newData = [];
// 遍历数据 转换对象格式
data.forEach((item)=>{
item.title = item.txt;
item.url = item.path;
item.opentype = item.type;
newData.push(item);
})
// 转换后将数据赋值到组件
this.setData({speakerMsgs:newData});
})
},
change : function(index){
console.log('切换到第 ' + index.detail + ' 个项目');
}
});.json
{
"usingComponents": {
"gracePage": "../../graceUI/components/gracePage",
"grace-speaker": "../../graceUI/components/graceSpeaker"
}
}