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>
    作者:银龙

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

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

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

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

  • 相关阅读:
    C#中正则表达式的使用
    Asp.Net MVC 身份验证-Forms
    ASP.NET MVC:窗体身份验证及角色权限管理示例
    asp.net mvc forms身份认证
    ASP.NET MVC Form验证
    C#进阶系列——WebApi 接口返回值不困惑:返回值类型详解
    参考例子,学习Func<T, TResult>委托
    Razor 中的@helper 与 @function 用法
    @Helper辅助方法和@functions自定义函数
    ASP.NET MVC传递参数(model), 如何保持TempData的持久性
  • 原文地址:https://www.cnblogs.com/wangyinlon/p/15179447.html
Copyright © 2011-2022 走看看