微信小程序:基础复习

设置底部导航栏

在这里插入图片描述

设置图标Icon属性

"iconPath":"icon/shouye.png",
"selectedIconPath":"icon/shouye.png"

基础组件

视图组件

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

轮播图组件

在这里插入图片描述
在这里插入图片描述
components/swiper/swiper.wxml

<!--components/swiper/swiper.wxml-->
<text>{{text}}</text>
<swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
    <view wx:for="{{list}}" wx:key="*this">
        <swiper-item>
            <image style="width: 100%; height: 200px;"  src="{{item}}" alt="img" />
        </swiper-item>
    </view>
</swiper>

components/swiper/swiper.ts

// components/swiper/swiper.ts

Component({
    /**
     * 组件的属性列表
     */
    properties: {
        text: {
            type: String,
            value: '轮播组件'
        },
        list: {
            type: Array,
            value: [],
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        indicatorDots: true,
        vertical: false,
        autoplay: false,
        interval: 2000,
        duration: 500
    },

    /**
     * 组件的方法列表
     */
    methods: {

    }
})

在页面中使用
在这里插入图片描述
pages/travel/travel.wxml

<!--pages/travel/travel.wxml-->
<text>pages/travel/travel.wxml</text>
<Swiper text="旅途攻略" list="{{list}}" />

pages/travel/travel.ts

// pages/travel/travel.ts


Page({

    /**
     * 页面的初始数据
     */
    data: {
        list: ['https://img0.baidu.com/it/u=530426417,2082848644&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
            'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp05%2F1910021352061916-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1656316971&t=f39466d70208ceb27fa6f8bebe645913', 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F4k%2Fs%2F02%2F2109242312005c1-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1656316971&t=88bc83e0116ca3a90b1e1a4cc582c6cd', 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp05%2F1910021221064F5-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1656317158&t=b733f1d81f31d7a487b5c3c46bfe0b46'],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})
{
  "usingComponents": {
    "Swiper": "../../components/swiper/swiper"
  }
}

子组件(自定义组件component)给父组件传递参数

components

<!--components/search/index.wxml-->
<text>components/search/index.wxml</text>
<input class="search" type="{{type}}" bindblur="getChangeValue" />

// components/search/index.ts
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        type: {
            type: String,
            value: 'text'
        }
    },

    /**
     * 组件的初始数据
     */
    data: {

    },

    /**
     * 组件的方法列表
     */
    methods: {
        getChangeValue (v) {
            console.log('v', v?.detail);
            this.triggerEvent('getSearchValue',v)
        }
    }
})

父组件

<!--pages/travel/travel.wxml-->
<text>pages/travel/travel.wxml</text>
<Swiper text="旅途攻略" list="{{list}}" />
<view></view>
<!-- 搜索栏 -->
<Search bind:getSearchValue="getSearhName" />
// pages/travel/travel.ts


Page({

    /**
     * 页面的初始数据
     */
    data: {
        list: ['https://img0.baidu.com/it/u=530426417,2082848644&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
            'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp05%2F1910021352061916-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1656316971&t=f39466d70208ceb27fa6f8bebe645913', 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F4k%2Fs%2F02%2F2109242312005c1-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1656316971&t=88bc83e0116ca3a90b1e1a4cc582c6cd', 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp05%2F1910021221064F5-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1656317158&t=b733f1d81f31d7a487b5c3c46bfe0b46'],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {
       
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },
    getSearhName(e){
        console.log('bbb',e);
    }
})
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值