在学习weex的过程中看到了常用标签相关的内容,为了自己以后能够快速查阅特整理出此文档。
a
- 简介
组件定义了指向某个页面的一个超链接. 此组件的作用和用法与HTML5中的 a
非常类似,区别在于 Weex 的 a 组件 不能 直接在里面添加文本(字符串),如果要展示文本,应该添加 text 组件。
- 示例代码
<template>
<div class="wrapper">
<a class="button" href="http://dotwe.org/raw/dist/3e0e40f9ddad79f98cd236753965ffd8.js">
<text class="text">Jump</text>
</a>
</div>
</template>
<style scoped>
.wrapper {
flex-direction: column;
justify-content: center;
}
.button {
width: 450px;
margin-top: 30px;
margin-left: 150px;
padding-top: 20px;
padding-bottom: 20px;
border-width: 2px;
border-style: solid;
border-color: #DDDDDD;
background-color: #F5F5F5
}
.text {
font-size: 60px;
color: #666666;
text-align: center;
}
</style>
slider
- 简介
slider 组件用于在一个页面中展示多个图片,在前端,这种效果被称为轮播图。
- 示例代码
<template>
<div>
<slider class="slider" interval="3000" auto-play="true">
<div class="frame" v-for="img in imageList">
<image class="image" resize="cover" :src="img.src"></image>
</div>
</slider>
</div>
</template>
<style scoped>
.image {
width: 700px;
height: 700px;
}
.slider {
margin-top: 25px;
margin-left: 25px;
width: 700px;
height: 700px;
border-width: 2px;
border-style: solid;
border-color: #41B883;
}
.frame {
width: 700px;
height: 700px;
position: relative;
}
</style>
<script>
export default {
data () {
return {
imageList: [
{ src: 'https://gd2.alicdn.com/bao/uploaded/i2/T14H1LFwBcXXXXXXXX_!!0-item_pic.jpg'},
{ src: 'https://gd1.alicdn.com/bao/uploaded/i1/TB1PXJCJFXXXXciXFXXXXXXXXXX_!!0-item_pic.jpg'},
{ src: 'https://gd3.alicdn.com/bao/uploaded/i3/TB1x6hYLXXXXXazXVXXXXXXXXXX_!!0-item_pic.jpg'}
]
}
}
}
</script>
indicator
- 简介
indicator 组件用于显示轮播图指示器效果,必须充当 slider
组件的子组件使用。
- 示例代码
<template>
<div>
<slider class="slider" interval="4500" @change="onchange">
<div class="frame" v-for="img in imageList">
<image class="image" resize="cover" :src="img.src"></image>
<text class="title">{{img.title}}</text>
</div>
<indicator class="indicator"></indicator>
</slider>
</div>
</template>
<style>
.image {
width: 700px;
height: 700px;
}
.slider {
margin-top: 25px;
margin-left: 25px;
width: 700px;
height: 700px;
border-width: 2px;
border-style: solid;
border-color: #41B883;
}
.title {
position: absolute;
top: 20px;
left: 20px;
padding-left: 20px;
width: 200px;
color: #FFFFFF;
font-size: 36px;
line-height: 60px;
background-color: rgba(0, 0, 0, 0.3);
}
.frame {
width: 700px;
height: 700px;
position: relative;
}
.indicator {
width: 700px;
height: 700px;
item-color: green;
item-selected-color: red;
item-size: 50px;
position: absolute;
top: 200px;
left: 200px;
}
</style>
<script>
export default {
data () {
return {
imageList: [
{ title: 'item A', src: 'https://gd2.alicdn.com/bao/uploaded/i2/T14H1LFwBcXXXXXXXX_!!0-item_pic.jpg'},
{ title: 'item B', src: 'https://gd1.alicdn.com/bao/uploaded/i1/TB1PXJCJFXXXXciXFXXXXXXXXXX_!!0-item_pic.jpg'},
{ title: 'item C', src: 'https://gd3.alicdn.com/bao/uploaded/i3/TB1x6hYLXXXXXazXVXXXXXXXXXX_!!0-item_pic.jpg'}
]
}
},
methods: {
onchange (event) {
console.log('changed:', event.index)
}
}
}
</script>
switch
- 简介
switch 是 Weex 的内置组件,用来创建与 iOS 一致样式的按钮。例如,在 iPhone 中的设置应用中的飞行模式按钮就是一个 switch 按钮。
- 示例代码
<template>
<div>
<div class="example">
<text class="label">normal</text>
<switch></switch>
</div>
<div class="example">
<text class="label">checked</text>
<switch checked="true" @change="onswitch"></switch>
<text class="info">{{haha}}</text>
</div>
<div class="example">
<text class="label">disabled</text>
<switch disabled="true" checked="true"></switch>
<switch disabled="true"></switch>
</div>
<div class="example">
<text class="label">onchange</text>
<switch @change="onchange"></switch>
<text class="info">{{checked}}</text>
</div>
</div>
</template>
<script>
export default {
data () {
return {
checked: false,
haha:true
}
},
methods: {
onchange (event) {
console.log(`onchage, value: ${event.value}`)
this.checked = event.value
},
onswitch (event) {
console.log(`onchage, value: ${event.value}`)
this.haha = event.value
}
}
}
</script>
<style scoped>
.example {
flex-direction: row;
justify-content: flex-start;
margin-top: 60px;
}
.label {
font-size: 40px;
line-height: 60px;
width: 350px;
color: #666;
text-align: right;
margin-right: 20px;
}
.info {
font-size: 30px;
line-height: 60px;
color: #BBB;
margin-left: 10px;
}
</style>
text
- 简介
text 是 Weex 内置的组件,用来将文本按照指定的样式渲染出来。text 只能包含文本值,你可以使用 {{}} 标记插入变量值作为文本内容。
- 示例代码 - iconfont
<template>
<scroller style='align-items:center'>
<div style='margin-top:20px'>
<text style="color:red;font-size:50px">only support font for ttf and woff</text>
</div>
<text class="title2" style='margin-top:50px;width:500px'>http ttf: </text>
<text class="title3" style='margin-top:50px;width:500px'>http woff: </text>
<div style='flex-direction:row;margin-top:50px'>
<text style='font-family:iconfont4;font-size:50;color:green'></text>
<text style='font-family:iconfont4;font-size:50;'></text>
<text style='font-family:iconfont4;font-size:60;color:blue'></text>
<text style='font-family:iconfont4;font-size:60;color:green'></text>
</div>
<div style='flex-direction:row;margin-top:50px'>
<text style='font-family:iconfont4;font-size:50;color:green'></text>
<text style='font-family:iconfont4;font-size:50;'></text>
<text style='font-family:iconfont4;font-size:60;color:blue'></text>
<text style='font-family:iconfont4;font-size:60;color:green'></text>
</div>
<div>
<text style='font-family:iconfont4;font-size:100; margin-top:50px'></text>
</div>
<div>
<text style='font-family:iconfont4;font-size:100;color:green;margin-top:50px'></text>
<text style='font-family:iconfont4;font-size:100;margin-top:50px'> </text>
</div>
<div style='flex-direction:row'>
<text style='font-family:iconfont4;font-size:70;width:750px'></text>
</div>
</scroller>
</template>
<style>
.title1 {
color: red;
font-size: 36;
font-family: iconfont1;
}
.title2 {
color: gray;
font-size: 36;
font-family: iconfont2;
}
.title3 {
color: pink;
font-size: 36;
font-family: iconfont3;
}
.title4 {
color: red;
font-size: 36;
font-family: iconfont4;
}
</style>
<script>
module.exports = {
mounted: function() {
var domModule = weex.requireModule('dom');
//目前支持ttf、woff文件,不支持svg、eot类型,moreItem at http://www.iconfont.cn/
domModule.addRule('fontFace', {
'fontFamily': "iconfont2",
'src': "url('http://at.alicdn.com/t/font_1469606063_76593.ttf')"
});
domModule.addRule('fontFace', {
'fontFamily': "iconfont3",
'src': "url('http://at.alicdn.com/t/font_1469606522_9417143.woff')"
});
domModule.addRule('fontFace', {
'fontFamily': "iconfont4",
'src': "url('http://at.alicdn.com/t/font_zn5b3jswpofuhaor.ttf')"
});
// you can use the absolute path or the local:// scheme path
// domModule.addRule('fontFace', {
// 'fontFamily': "iconfont4",
// 'src': "url('file:///storage/emulated/0/Android/data/com.alibaba.weex/cache/http:__at.alicdn.com_t_font_1469606063_76593.ttf')"
// });
}
}
</script>
- 示例代码 - normal Text
<template>
<div class="wrapper">
<div class="panel">
<text class="text" lines="5">Weex 是一套简单易用的跨平台开发方案,能以 Web 的开发体验构建高性能、可扩展的原生应用。Vue 是一个轻量并且功能强大的渐进式前端框架。</text>
</div>
<div class="panel">
<text class="text" lines="3">Weex is an cross-platform development solution that builds high-performance, scalable native applications with a Web development experience. Vue is a lightweight and powerful progressive front-end framework. </text>
</div>
</div>
</template>
<style scoped>
.wrapper {
flex-direction: column;
justify-content: center;
}
.panel {
width: 600px;
margin-left: 75px;
border-width: 2px;
border-style: solid;
border-color: #BBB;
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
padding-right: 15px;
margin-bottom: 30px;
}
.text {
lines: 5;
color: #666666;
font-size: 32px;
}
</style>
textarea
- 简介
textarea 是 Weex 内置的一个组件,用于用户交互,接受用户输入数据。 可以认为是允许多行的 input Notes: textarea支持input支持的所有的事件。
- 示例代码
<template>
<div class="wrapper">
<textarea class="textarea" @input="oninput" @change="onchange" @focus="onfocus" @blur="onblur"></textarea>
</div>
</template>
<script>
const modal = weex.requireModule('modal')
export default {
methods: {
oninput (event) {
console.log('oninput:', event.value)
modal.toast({
message: `oninput: ${event.value}`,
duration: 0.8
})
},
onchange (event) {
console.log('onchange:', event.value)
modal.toast({
message: `onchange: ${event.value}`,
duration: 0.8
})
},
onfocus (event) {
console.log('onfocus:', event.value)
modal.toast({
message: `onfocus: ${event.value}`,
duration: 0.8
})
},
onblur (event) {
console.log('onblur:', event.value)
modal.toast({
message: `input blur: ${event.value}`,
duration: 0.8
})
}
}
}
</script>
<style>
.textarea {
font-size: 50px;
width: 650px;
margin-top: 50px;
margin-left: 50px;
padding-top: 20px;
padding-bottom: 20px;
padding-left: 20px;
padding-right: 20px;
color: #666666;
border-width: 2px;
border-style: solid;
border-color: #41B883;
}
</style>
video
- 简介
video组件可以让我们在 Weex 页面中嵌入视频内容。text 是唯一合法的子组件。
- 示例代码
<template>
<div>
<video class="video" :src="src" autoplay controls
@start="onstart" @pause="onpause" @finish="onfinish" @fail="onfail"></video>
<text class="info">state: {{state}}</text>
</div>
</template>
<style scoped>
.video {
width: 630px;
height: 350px;
margin-top: 60px;
margin-left: 60px;
}
.info {
margin-top: 40px;
font-size: 40px;
text-align: center;
}
</style>
<script>
export default {
data () {
return {
state: '----',
src:'http://flv2.bn.netease.com/videolib3/1611/01/XGqSL5981/SD/XGqSL5981-mobile.mp4'
}
},
methods:{
onstart (event) {
this.state = 'onstart'
},
onpause (event) {
this.state = 'onpause'
},
onfinish (event) {
this.state = 'onfinish'
},
onfail (event) {
this.state = 'onfinish'
}
}
}
</script>
web
- 简介
使用 web 组件在 Weex 页面中嵌入一张网页内容。 src 属性用来指定资源地址。你也可以使用 webview module 来控制 web 的行为,比如前进、后退和重载。可以在这里查看 webview module。
- 示例代码
<template>
<div class="wrapper">
<div class="group">
<input class="input" v-model="value" ref="input" type="url" autofocus="false"></input>
</div>
<div class="group">
<text class="button" @click="loadURL">LoadURL</text>
<text class="button" @click="reload">reload</text>
</div>
<web ref="webview" :src="url" class="webview" @pagestart="start" @pagefinish="finish" @error="error"></web>
</div>
</template>
<script>
const webview = weex.requireModule('webview')
const modal = weex.requireModule('modal')
export default {
data () {
return {
url : 'https://m.alibaba.com',
value: 'https://m.alibaba.com'
}
},
methods: {
loadURL (event) {
this.url = this.value
modal.toast({ message: 'load url:' + this.url })
setTimeout(() => {
console.log('will go back.')
modal.toast({ message: 'will go back' })
webview.goBack(this.$refs.webview)
}, 10000)
},
reload (event) {
console.log('will reload webview')
modal.toast({ message: 'reload' })
webview.reload(this.$refs.webview)
},
start (event) {
console.log('pagestart', event)
modal.toast({ message: 'pagestart' })
},
finish (event) {
console.log('pagefinish', event)
modal.toast({ message: 'pagefinish' })
},
error (event) {
console.log('error', event)
modal.toast({ message: 'error' })
}
}
}
</script>
<style scoped>
.group {
flex-direction: row;
justify-content: space-around;
margin-top: 20px;
}
.input {
width: 600px;
font-size: 36px;
padding-top: 15px;
padding-bottom: 15px;
border-width: 2px;
border-style: solid;
border-color: #BBBBBB;
}
.button {
width: 225px;
text-align: center;
background-color: #D3D3D3;
padding-top: 15px;
padding-bottom: 15px;
margin-bottom: 30px;
font-size: 30px;
}
.webview {
margin-left: 75px;
width: 600px;
height: 750px;
border-width: 2px;
border-style: solid;
border-color: #41B883;
}
</style>
div
- 简介
div 组件是用于包装其它组件的最基本容器。支持所有的通用样式、特性、flexbox 布局。其类似于 HTML 的 div 容器,但不能直接在里面添加文本(字符串),如果要展示文本,应该使用 text 组件。历史版本中,div 别名是 container,目前已经弃用。
注意:
div 嵌套层级不可过深,否则容易引起性能问题,建议控制在 10 层以内。
- 示例代码
<template>
<div>
<text class="text">Hello World!</text>
</div>
</template>
<style>
.text {
font-size: 70px;
color: #ff0000
}
</style>
<script></script>
image
- 简介
image 组件用于渲染图片,并且它不能包含任何子组件。新版 Vue 2.0 中不支持用 img 作简写。需要注意的是,需要明确指定 width 和 height,否则图片无法显示。
- 示例代码
<template>
<div>
<div>
<text>cover</text>
<image resize="cover" class="cover" src="https://img.alicdn.com/tps/TB1z.55OFXXXXcLXXXXXXXXXXXX-560-560.jpg"></image>
</div>
<div>
<text>contain</text>
<image resize="contain" class="contain" src="https://img.alicdn.com/tps/TB1z.55OFXXXXcLXXXXXXXXXXXX-560-560.jpg"></image>
</div>
</div>
</template>
<style>
.cover {
width:750px;
height:500px;
border-width: 2px;
border-style: solid;
border-color: #ff0000;
}
.contain {
width:750px;
height:500px;
border-width: 2px;
border-style: solid;
border-color: #ff0000;
}
</style>
<script>
</script>
input
- 简介
Weex 内置的 input 组件用来创建接收用户输入字符的输入组件。 input 组件的工作方式因 type 属性的值而异,比如 text, password,url,email,tel 等。
注意:
此组件不支持 click 事件。请监听 <input> 或 change 来代替 click 事件。
- 示例代码
<template>
<div>
<div>
<text style="font-size: 40px">oninput: {{txtInput}}</text>
<text style="font-size: 40px">onchange: {{txtChange}}</text>
<text style="font-size: 40px">onreturntype: {{txtReturnType}}</text>
</div>
<scroller>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80 ;padding: 20;color: #FFFFFF">input type = text</text>
</div>
<input type="text" placeholder="Input Text" class="input" :autofocus=true value="" @change="onchange" @input="oninput" @focus="onfocus" @blur="onblur"/>
</div>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80 ;padding: 20;color: #FFFFFF">input type = password</text>
</div>
<input type="password" placeholder="Input Password" class="input" @change="onchange" @input="oninput"/>
</div>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80 ;padding: 20;color: #FFFFFF">input type = url</text>
</div>
<input type="url" placeholder="Input URL" class="input" @change="onchange" @input="oninput"/>
</div>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80 ;padding: 20;color: #FFFFFF">input type = email</text>
</div>
<input type="email" placeholder="Input Email" class="input" @change="onchange" @input="oninput"/>
</div>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80 ;padding: 20;color: #FFFFFF">input type = tel</text>
</div>
<input type="tel" placeholder="Input Tel" class="input" @change="onchange" @input="oninput"/>
</div>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80 ;padding: 20;color: #FFFFFF">input type = time</text>
</div>
<input type="time" placeholder="Input Time" class="input" @change="onchange" @input="oninput"/>
</div>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80 ;padding: 20;color: #FFFFFF">input type = date</text>
</div>
<input type="date" placeholder="Input Date" class="input" @change="onchange" @input="oninput" max="2017-12-12" min="2015-01-01"/>
</div>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80 ;padding: 20;color: #FFFFFF">input return-key-type = default</text>
</div>
<input type="text" placeholder="please input" return-key-type="default" class="input" @change="onchange" @return = "onreturn" @input="oninput" />
</div>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80 ;padding: 20;color: #FFFFFF">input return-key-type = go</text>
</div>
<input type="text" placeholder="please input" return-key-type="go" class="input" @change="onchange" @return = "onreturn" @input="oninput" />
</div>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80 ;padding: 20;color: #FFFFFF">input return-key-type = next</text>
</div>
<input type="text" placeholder="please input" return-key-type="next" class="input" @change="onchange" @return = "onreturn" @input="oninput" />
</div>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80 ;padding: 20;color: #FFFFFF">input return-key-type = search</text>
</div>
<input type="text" placeholder="please input" return-key-type="search" class="input" @change="onchange" @return = "onreturn" @input="oninput" />
</div>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80 ;padding: 20;color: #FFFFFF">input return-key-type = send</text>
</div>
<input type="text" placeholder="please input" return-key-type="send" class="input" @change="onchange" @return = "onreturn" @input="oninput" />
</div>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80 ;padding: 20;color: #FFFFFF">input return-key-type = done</text>
</div>
<input type="text" placeholder="please input" return-key-type="done" class="input" @change="onchange" @return = "onreturn" @input="oninput" />
</div>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80 ;padding: 20;color: #FFFFFF">function focus() & blur()</text>
</div>
<div style="flex-direction: row;margin-bottom: 16px;justify-content: space-between">
<text class="button" value="Focus" type="primary" @click="focus"></text>
<text class="button" value="Blur" type="primary" @click="blur"></text>
</div>
<input type="text" placeholder="Input1" class="input" value="" ref="input1"/>
</div>
<div>
<div style="background-color: #286090">
<text class="title" style="height: 80 ;padding: 20;color: #FFFFFF">input selection</text>
</div>
<div style="flex-direction: row;margin-bottom: 16px;justify-content: space-between">
<text class="button" value="setRange" type="primary" @click="setRange"></text>
</div>
<input type="text" ref="inputselection" placeholder="please input" value="123456789" class="input" @change="onchange" @return = "onreturn" @input="oninput"/>
</div>
</scroller>
</div>
</template>
<style scoped>
.input {
font-size: 60px;
height: 80px;
width: 750px;
}
.button {
font-size: 36;
width: 200;
color: #41B883;
text-align: center;
padding-top: 10;
padding-bottom: 10;
border-width: 2;
border-style: solid;
margin-right: 20;
border-color: rgb(162, 217, 192);
background-color: rgba(162, 217, 192, 0.2);
}
</style>
<script>
const modal = weex.requireModule('modal')
module.exports = {
data: function () {
return {
txtInput: '',
txtChange: '',
txtReturnType: '',
txtSelection:'',
autofocus: false
};
},
methods: {
ready: function () {
var self = this;
setTimeout(function () {
self.autofocus = true;
}, 1000);
},
onchange: function (event) {
this.txtChange = event.value;
console.log('onchange', event.value);
},
onreturn: function (event) {
this.txtReturnType = event.returnKeyType;
console.log('onreturn', event.type);
},
oninput: function (event) {
this.txtInput = event.value;
console.log('oninput', event.value);
},
focus: function () {
this.$refs['input1'].focus();
},
blur: function () {
this.$refs['input1'].blur();
},
setRange: function() {
console.log(this.$refs["inputselection"]);
this.$refs["inputselection"].setSelectionRange(2, 6);
},
onfocus () {
console.log('onfocus:');
modal.toast({
message: 'onfocus',
duration: 0.8
})
},
onblur () {
console.log('onblur:');
modal.toast({
message: 'input blur',
duration: 0.8
})
}
}
};
</script>
list
- 简介
- 支持上拉加载更多 示例代码
<template>
<list class="list" @loadmore="fetch" loadmoreoffset="10">
<cell class="cell" v-for="num in lists">
<div class="panel">
<text class="text">{{num}}</text>
</div>
</cell>
</list>
</template>
<script>
const modal = weex.requireModule('modal')
const LOADMORE_COUNT = 4
export default {
data () {
return {
lists: [1, 2, 3, 4, 5]
}
},
methods: {
fetch (event) {
modal.toast({ message: 'loadmore', duration: 1 })
setTimeout(() => {
const length = this.lists.length
for (let i = length; i < length + LOADMORE_COUNT; ++i) {
this.lists.push(i + 1)
}
}, 800)
}
}
}
</script>
<style scoped>
.panel {
width: 600px;
height: 250px;
margin-left: 75px;
margin-top: 35px;
margin-bottom: 35px;
flex-direction: column;
justify-content: center;
border-width: 2px;
border-style: solid;
border-color: rgb(162, 217, 192);
background-color: rgba(162, 217, 192, 0.2);
}
.text {
font-size: 50px;
text-align: center;
color: #41B883;
}
</style>
- 带网络请求的示例
<template>
<list class="list" @loadmore="fetch" loadmoreoffset="10">
<cell class="cell" v-for="num in lists">
<div class="panel">
<text class="text">{{num}}</text>
</div>
</cell>
</list>
</template>
<script>
const modal = weex.requireModule('modal')
const LOADMORE_COUNT = 4
export default {
data () {
return {
lists: [1, 2, 3, 4, 5]
}
},
methods: {
fetch (event) {
modal.toast({ message: 'loadmore', duration: 1 })
setTimeout(() => {
const length = this.lists.length
for (let i = length; i < length + LOADMORE_COUNT; ++i) {
this.lists.push(i + 1)
}
}, 800)
}
}
}
</script>
<style scoped>
.panel {
width: 600px;
height: 250px;
margin-left: 75px;
margin-top: 35px;
margin-bottom: 35px;
flex-direction: column;
justify-content: center;
border-width: 2px;
border-style: solid;
border-color: rgb(162, 217, 192);
background-color: rgba(162, 217, 192, 0.2);
}
.text {
font-size: 50px;
text-align: center;
color: #41B883;
}
</style>
cell
- 简介
用于定义列表中的子列表项,类似于 HTML 中的 ul之于 li。Weex 会对 cell 进行高效的内存回收以达到更好的性能,该组件必须作为list 组件的子组件, 这是为了优化滚动时的性能。
支持所有 Weex 的组件作为它的子组件。
属性keep-scroll-position {boolean}: List 插入数据后是否保持上次滚动的位置。
- 示例代码
<template>
<list class="list" @loadmore="fetch" loadmoreoffset="10">
<cell class="cell" v-for="num in lists">
<div class="panel">
<text class="text">{{num}}</text>
</div>
</cell>
</list>
</template>
<script>
const modal = weex.requireModule('modal')
const LOADMORE_COUNT = 4
export default {
data () {
return {
lists: [1, 2, 3, 4, 5]
}
},
methods: {
fetch (event) {
modal.toast({ message: 'loadmore', duration: 1 })
setTimeout(() => {
const length = this.lists.length
for (let i = length; i < length + LOADMORE_COUNT; ++i) {
this.lists.push(i + 1)
}
}, 800)
}
}
}
</script>
<style scoped>
.panel {
width: 600px;
height: 250px;
margin-left: 75px;
margin-top: 35px;
margin-bottom: 35px;
flex-direction: column;
justify-content: center;
border-width: 2px;
border-style: solid;
border-color: rgb(162, 217, 192);
background-color: rgba(162, 217, 192, 0.2);
}
.text {
font-size: 50px;
text-align: center;
color: #41B883;
}
</style>
refresh
- 简介
<refresh>为 <scroller>和 <list>提供下拉加载功能。用法与特性与 <loading>类似,<scroller>和 <list> 的子组件,且只能在被 <scroller> 和 <list> 包含时才能被正确的渲染。
- 示例代码
<template>
<scroller class="scroller">
<refresh class="refresh" @refresh="onrefresh" @pullingdown="onpullingdown" :display="refreshing ? 'show' : 'hide'">
<text class="indicator">Refreshing ...</text>
</refresh>
<div class="cell" v-for="num in lists">
<div class="panel">
<text class="text">{{num}}</text>
</div>
</div>
</scroller>
</template>
<script>
const modal = weex.requireModule('modal')
export default {
data () {
return {
refreshing: false,
lists: [1, 2, 3, 4, 5]
}
},
methods: {
onrefresh (event) {
console.log('is refreshing')
modal.toast({ message: 'refresh', duration: 1 })
this.refreshing = true
setTimeout(() => {
this.refreshing = false
}, 2000)
},
onpullingdown (event) {
console.log('is onpulling down')
modal.toast({ message: 'pulling down', duration: 1 })
}
}
}
</script>
<style scoped>
.indicator {
color: #888888;
font-size: 42px;
text-align: center;
}
.panel {
width: 600px;
height: 250px;
margin-left: 75px;
margin-top: 35px;
margin-bottom: 35px;
flex-direction: column;
justify-content: center;
border-width: 2px;
border-style: solid;
border-color: #DDDDDD;
background-color: #F5F5F5;
}
.text {
font-size: 50px;
text-align: center;
color: #41B883;
}
</style>
scroller
- 简介
scroller 是一个竖直的,可以容纳多个排成一列的子组件的滚动器。如果子组件的总高度高于其本身,那么所有的子组件都可滚动。
注意: scroller 可以当作根元素或者嵌套元素使用。此组件的滚动方向是垂直方向的形式。
- 示例代码
<template>
<div class="wrapper">
<scroller class="scroller">
<div class="row" v-for="(name, index) in rows" :ref="'item'+index">
<text class="text" :ref="'text'+index">{{name}}</text>
</div>
</scroller>
<div class="group">
<text @click="goto10" class="button">Go to 10</text>
<text @click="goto20" class="button">Go to 20</text>
</div>
</div>
</template>
<script>
const dom = weex.requireModule('dom')
export default {
data () {
return {
rows: []
}
},
created () {
for (let i = 0; i < 30; i++) {
this.rows.push('row ' + i)
}
},
methods: {
goto10 (count) {
const el = this.$refs.item10[0]
dom.scrollToElement(el, {})
},
goto20 (count) {
const el = this.$refs.item20[0]
dom.scrollToElement(el, { offset: 0 })
}
}
}
</script>
<style scoped>
.scroller {
width: 700px;
height: 700px;
border-width: 3px;
border-style: solid;
border-color: rgb(162, 217, 192);
margin-left: 25px;
}
.row {
height: 100px;
flex-direction: column;
justify-content: center;
padding-left: 30px;
border-bottom-width: 2px;
border-bottom-style: solid;
border-bottom-color: #DDDDDD;
}
.text {
font-size: 45px;
color: #666666;
}
.group {
flex-direction: row;
justify-content: center;
margin-top: 60px;
}
.button {
width: 200px;
padding-top: 20px;
padding-bottom: 20px;
font-size: 40px;
margin-left: 30px;
margin-right: 30px;
text-align: center;
color: #41B883;
border-width: 2px;
border-style: solid;
border-color: rgb(162, 217, 192);
background-color: rgba(162, 217, 192, 0.2);
}
</style>