Vue.js学习之路
下面的内容主要是把数据保存到本地并且删除,以及在网页上调取api获取里面的内容的方法。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| <template> <view> <button type="primary" @tap="setValue">设置数据</button> <button type="primary" @tap="getValue">获取数据</button> <view> {{getmsg}} </view> <view> {{getmsg2}} </view> <br> <button type="primary" @tap="removeValue">删除数据(一个一个删除)</button> <button type="primary" @tap="clearValue">删除数据(全部删除)</button> <br> <button type="primary" @tap="setArrValue">设置数组长度</button> <button type="primary" @tap="getArrValue">获取数组长度</button> <view> {{showArray}} </view> </view> </template> <script> export default { data() { return { msg:"Hello World!", msg2:"你好世界", getmsg:"", getmsg2:"", array:[ {name:"jack",sex:"m"}, {name:"lucy",sex:"w"}, {name:"lisa",sex:"w"} ], showArray:"", } }, onLoad() { }, methods: { setValue(){ uni.setStorageSync("mykey",this.msg) uni.setStorageSync("mykey2",this.msg2) }, getValue(){ this.getmsg = uni.getStorageSync("mykey") this.getmsg2 = uni.getStorageSync("mykey2") }, removeValue(){ uni.removeStorageSync("mykey") }, clearValue(){ uni.clearStorageSync() }, setArrValue(){ uni.setStorageSync("myArr",JSON.stringify(this.array)) }, getArrValue(){ this.showArray = uni.getStorageSync("myArr") } } } </script> <style> </style>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| <template> <view> <view class="list-dmeo" v-for="item,index in arrList" :key="index"> <image src="../../static/say.jpg" class="limit-img"></image> <view class="right-dec"> <view class="top-title">书名:{{item.bookName}}</view> <view class="top-author">作者:{{item.author}}</view> <view class="right-price">排名:{{item.ranking}}</view> <view class="right-price">阅读量:{{item.read}}</view> <view class="right-price">热门好书:{{item.dec}}</view> </view> </view> </view> </template> <script> export default { data() { return { arrList:"" } }, created() { this.constApi(); }, methods: { constApi(){ uni.request({ url:"../../static/server.json", method:'GET', data:{}, success:res=>{ console.log(res); console.log(res.date); this.arrList = res.data.data; }, fail: () => { }, complete: () => { } }); } } } </script> <style> .list-dmeo { display: flex; margin-bottom: 20rpx; } .limit-img { width: 200rpx; height: 300rpx; } .right-dec { padding-top: 20rpx; padding-left: 20rpx; padding-bottom: 20rpx; flex-direction: column; display: flex; justify-content: space-between; } .top-title { font-size: 32rpx; font-weight: bold; } .top-author { font-size: 30rpx; font-weight: bold; } .right-price { font-size: 26rpx; font-weight: bold; } </style>
|