欢迎来到银龙的博客

人生三从境界:昨夜西风凋碧树,独上高楼,望尽天涯路。 衣带渐宽终不悔,为伊消得人憔悴。 众里寻他千百度,蓦然回首,那人却在灯火阑珊处。

uniapp方法回调success不能用this记录

 

报错

 

 

<template>
    <view >
    首页
    </view>
</template>

<script>
    export default {
        data() {
            return {
                title: 'Hello',
                swipers:[]
            }
        },
        onLoad() {
            this.getSwipers()

        },
        methods: {
            //获取轮播图的数据
            getSwipers(){
                console.log("获取轮播")
                uni.request({
                    url:"https://www.baidu.com/",
                    success:function(res){
                        console.log("添加数组")
                        this.swipers.push("static/lunbo/bg1.jpg");
                        this.swipers.push("static/lunbo/hx1.jpg");
                        this.swipers.push("static/lunbo/hx2.jpg");
                    },
            
                })
            }

        }
    }
</script>

<style>

</style>

 

正常

 

<template>
    <view >
    首页
    </view>
</template>

<script>
    export default {
        data() {
            return {
                title: 'Hello',
                swipers:[]
            }
        },
        onLoad() {
            this.getSwipers()

        },
        methods: {
            //获取轮播图的数据
            getSwipers(){
                var thi=this
                console.log("获取轮播")
                uni.request({
                    url:"https://www.baidu.com/",
                    success:function(res){
                        console.log("添加数组")
                        thi.swipers.push("static/lunbo/bg1.jpg");
                        thi.swipers.push("static/lunbo/hx1.jpg");
                        thi.swipers.push("static/lunbo/hx2.jpg");
                    },
            
                })
            }

        }
    }
</script>

<style>

</style>

 

正常2

 

<template>
    <view >
    首页
    </view>
</template>

<script>
    export default {
        data() {
            return {
                title: 'Hello',
                swipers:[]
            }
        },
        onLoad() {
            this.getSwipers()

        },
        methods: {
            //获取轮播图的数据
            getSwipers(){
                console.log("获取轮播")
                uni.request({
                    url:"https://www.baidu.com/",
                    success:res=>{
                    console.log("添加数组")
                    this.swipers.push("static/lunbo/bg1.jpg");
                    this.swipers.push("static/lunbo/hx1.jpg");
                    this.swipers.push("static/lunbo/hx2.jpg");
                },
            
                })
            }

        }
    }
</script>

<style>

</style>

 

posted on 2021-08-24 11:13  银龙科技  阅读(1184)  评论(0编辑  收藏  举报

导航