Code Monkey home page Code Monkey logo

Comments (9)

bestony avatar bestony commented on August 30, 2024

modal: true,时,就不会显示这个了,
wx.request 这个请求中,如果success,就会设置为true,失败时会设置为 modal: false。不过我或许应该优化一下,失败时同时让Loading消失,等会回来改。

from weapp-v2ex.

jonahfang avatar jonahfang commented on August 30, 2024

@bestony ,谢谢这么快就回复。我看了下面的代码:

    Request: function() {
        var that = this;
        wx.request( {
            url: "https://www.v2ex.com/api/topics/hot.json",
            success: function( data ) {
                that.setData( {
                    datas: data.data,
                    loading: true,
                    modal: true,
                })
            },
            fail: function( data ) {
                that.setData( {
                    modal: false
                })
            }
        })
    },

正常流程应该是:
1.开始请求前,应该显示loading(不显示modal)
2.请求成功后(success): 应该关闭loading.
3.请求失败后(fail): 应该关闭loading,显示modal.

但上述流程在程序中好像看不出来。

from weapp-v2ex.

bestony avatar bestony commented on August 30, 2024

在初始设置data时会给modal和loading,Loading为显示,Modal为隐藏。具体在第四行和第五行。wx,request成功后,modal不变,loading隐藏。失败时,通过设置modal的值,显示modal,并绑定请求。关闭Loading是我之前没注意,没做好。

from weapp-v2ex.

jonahfang avatar jonahfang commented on August 30, 2024

不好意思,我看错变量名了, loading/modal 为真都表示hidden.

from weapp-v2ex.

jonahfang avatar jonahfang commented on August 30, 2024

应该变量名命名为 loadingHidden, modalHidden

from weapp-v2ex.

jonahfang avatar jonahfang commented on August 30, 2024

改成这样,调试通过:

    data: {
        datas: [],
        loadingHidden: true,
        modalHidden: true
    },
    onLoad: function( options ) {
        var that = this;
        that.Request();
    },
    Request: function() {
        var that = this;
        that.setData( {
            loadingHidden: false
        })
        wx.request( {
            url: "https://www.v2ex.com/api/topics/hot.json",
            success: function( data ) {
                that.setData( {
                    datas: data.data,
                    loadingHidden: true
                })
            },
            fail: function( data ) {
                that.setData( {
                    loadingHidden: true,
                    modalHidden: false
                })
            }
        })
    },

from weapp-v2ex.

jonahfang avatar jonahfang commented on August 30, 2024

再改进一下:

    Request: function() {
        var that = this;
        that.setData( {
            loadingHidden: false,
            modalHidden: true    <---- 加这个
        })

from weapp-v2ex.

bestony avatar bestony commented on August 30, 2024

对,我需要加这个,你不如提交pr,我来合并。省的我等会回去改😃。不过可能要看下各个wxml和js

from weapp-v2ex.

bestony avatar bestony commented on August 30, 2024

对了,今晚八点,熊猫TV,364844房间。直播撸小程序

from weapp-v2ex.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.