百度小程序常用操作手册

点击功能

bind:tap="mclick" class="{{bg ? 's1':'m-click-this'}}"

用css来判断显示隐藏

然后在js文件内

data: { 
        age: 1,
        gameUrl:app.gameUrl,
        title:app.title,
        bg: true//默认为true
    },
mclick : function(){
            this.setData({
              bg : !this.data.bg//点击后则切换相当于jq的toggle
            })
        }


模板功能

在json文件内

{
    "usingComponents": {
        "head": "/moban/head/head"//引入的路径
} 
}

html文件内

<head></head>

即可!


banner功能

结合后台

先定义一个imgs:[],

swan.request({
            url: app.gameUrl + '/plus/type_ajax.php',
            method: 'GET',
            dataType: 'json',
            data:{
              banner:'banner',
              typeid:4
            },
            header: {
                'content-type': 'application/json' // 默认值
            },
            success:function(res){
                _this.setData({
                   imgs:res.data.data
                })
            },
             fail: function (err) {
                console.log('错误码:' + err.errCode);
                console.log('错误信息:' + err.errMsg);
            }
        });

然后循环输出

 <block s-for="imgUrl in imgs">
    <swiper-item>
            <image src="{{gameUrl}}{{imgUrl.logo}}" mode="widthFix" class="slide-image" width="750" height="auto" />
        </swiper-item>
</block>


相关内容

发表评论

验证码:
点击我更换图片

最新评论