swiper.uvue 4.2 KB
Newer Older
杜庆泉's avatar
杜庆泉 已提交
1 2 3 4
<template>
	<view>
		<page-head title="swiper,可滑动视图"></page-head>
		<view class="uni-margin-wrap">
杜庆泉's avatar
杜庆泉 已提交
5 6
			<swiper class="swiper" :vertical="verticalSelect" :indicator-dots="dotsSelect" :autoplay="autoplaySelect" :interval="intervalSelect"  :circular="circularSelect" :indicator-color="indicatorColor" :indicator-active-color="indicatorColorActive" :current="currentVal" :current-item-id="currentItemIdVal">
				<swiper-item item-id="A">
杜庆泉's avatar
杜庆泉 已提交
7 8
					<view class="swiper-item uni-bg-red">A</view>
				</swiper-item>
杜庆泉's avatar
杜庆泉 已提交
9
				<swiper-item item-id="B">
杜庆泉's avatar
杜庆泉 已提交
10 11
					<view class="swiper-item uni-bg-green">B</view>
				</swiper-item>
杜庆泉's avatar
杜庆泉 已提交
12
				<swiper-item item-id="C">
杜庆泉's avatar
杜庆泉 已提交
13 14 15 16
					<view class="swiper-item uni-bg-blue">C</view>
				</swiper-item>
			</swiper>
		</view>
杜庆泉's avatar
杜庆泉 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
		<view class="uni-list">
		  <view class="uni-list-cell uni-list-cell-pd">
		    <view class="uni-list-cell-db">是否显示面板指示点</view>
		    <switch :checked="dotsSelect" @change="dotsChange"/>
		  </view>
		  <view class="uni-list-cell uni-list-cell-pd">
		    <view class="uni-list-cell-db">是否自动切换</view>
		    <switch :checked="autoplaySelect" @change="autoplayChange"/>
		  </view>
		  <view class="uni-list-cell uni-list-cell-pd">
		    <view class="uni-list-cell-db">是否循环</view>
		    <switch :checked="circularSelect" @change="circularChange"/>
		  </view>
		  <view class="uni-title">间隔时间</view>
		  <view>
		    <slider @change="sliderChange" :value="1000" :min="500" :max="5000" :show-value="true" />
		  </view>
		  <view class="uni-list-cell uni-list-cell-pd">
		    <view class="uni-list-cell-db">定制指示器颜色</view>
		    <switch :checked="indicatorColorSelect" @change="indicatorColorChange"/>
		  </view>
杜庆泉's avatar
杜庆泉 已提交
38 39 40 41 42 43 44 45 46 47 48 49
		  <view class="uni-list-cell uni-list-cell-pd">
		    <view class="uni-list-cell-db">纵向</view>
		    <switch :checked="verticalSelect" @change="verticalChange"/>
		  </view>
		  <view class="uni-list-cell uni-list-cell-pd">
		    <view class="uni-list-cell-db">指定current为最后一个元素</view>
		    <switch :checked="currentSelect" @change="currentChange"/>
		  </view>
		  <view class="uni-list-cell uni-list-cell-pd">
		    <view class="uni-list-cell-db">指定current-item-id为最后一个元素</view>
		    <switch :checked="currentItemIdSelect" @change="currentItemIdChange"/>
		  </view>
杜庆泉's avatar
杜庆泉 已提交
50 51
		  
		</view>
杜庆泉's avatar
杜庆泉 已提交
52 53 54 55 56 57 58 59 60 61


	</view>
</template>
<script>
	export default {
		data() {
			return {
				background: ['color1', 'color2', 'color3'],
				interval: 2000,
杜庆泉's avatar
杜庆泉 已提交
62 63 64 65
				dotsSelect:false,
				autoplaySelect:false,
				circularSelect:false,
				indicatorColorSelect:false,
杜庆泉's avatar
杜庆泉 已提交
66 67 68
				verticalSelect:false,
				currentSelect:false,
				currentItemIdSelect:false,
杜庆泉's avatar
杜庆泉 已提交
69 70 71
				intervalSelect:1000,
				indicatorColor:"",
				indicatorColorActive:"",
杜庆泉's avatar
杜庆泉 已提交
72 73
				currentVal:0,
				currentItemIdVal:""
杜庆泉's avatar
杜庆泉 已提交
74 75 76
			}
		},
		methods: {
杜庆泉's avatar
杜庆泉 已提交
77 78 79 80 81 82
			dotsChange: function (e : SwitchChangeEvent) {
				this.dotsSelect = e.detail.value
			},
			autoplayChange: function (e : SwitchChangeEvent) {
				this.autoplaySelect = e.detail.value
			},
杜庆泉's avatar
杜庆泉 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
			verticalChange: function (e : SwitchChangeEvent) {
				this.verticalSelect = e.detail.value
			},
			currentItemIdChange: function (e : SwitchChangeEvent) {
				this.currentItemIdSelect = e.detail.value
				if(this.currentItemIdSelect){
					this.currentItemIdVal = 'C'
				}else{
					this.currentItemIdVal = 'A'
				}
			},
			currentChange: function (e : SwitchChangeEvent) {
				this.currentSelect = e.detail.value
				if(this.currentSelect){
					this.currentVal = 2
				}else{
					this.currentVal = 0
				}
				
			},
杜庆泉's avatar
杜庆泉 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
			circularChange: function (e : SwitchChangeEvent) {
				this.circularSelect = e.detail.value
				console.log(this.circularSelect)
			},
			sliderChange(e : SliderChangeEvent) {
			  this.intervalSelect = e.detail.value
			},
			indicatorColorChange(e : SwitchChangeEvent) {
				this.indicatorColorSelect = e.detail.value
				if(this.indicatorColorSelect){
					// 选择了定制指示器颜色
					this.indicatorColor = "#ff00ff"
					this. indicatorColorActive = "#0000ff"
				}else{
					// 没有选择颜色
					this.indicatorColor = ""
					this. indicatorColorActive = ""
				}
			}
杜庆泉's avatar
杜庆泉 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134
		}
	}
</script>

<style>
	.uni-margin-wrap {
		width:690rpx;
		width: 100%;;
	}
	.swiper {
		height: 300rpx;
	}
	.swiper-item {
杜庆泉's avatar
杜庆泉 已提交
135
		width: 100%;
杜庆泉's avatar
杜庆泉 已提交
136 137 138 139 140 141
		height: 300rpx;
		line-height: 300rpx;
		text-align: center;
	}

</style>