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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM