zoukankan      html  css  js  c++  java
  • 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>
    作者:银龙

    -------------------------------------------

    个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!

    如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!

    万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!

  • 相关阅读:
    mysql数据库 表 导入导出
    Java爬虫
    oracle 表空间统计、自动扩展修改
    dba_segements 没有所有的表的信息
    html&css基础框架
    javascript-ajax之json学习笔记
    符合BME风格的弹窗菜单表格文件上传控件
    iframe元素获取
    文件上传与下载
    JSON.parse 函数
  • 原文地址:https://www.cnblogs.com/wangyinlon/p/15179447.html
Copyright © 2011-2022 走看看