豫ICP备2024044691号-1
powered by emlog
微信小程序填坑日记 - 长期更新
Mins 2024-3-17 23:38 微信开发

1、ios中,new Date对象中的参数,必须是 yyyy mm dd 格式,否则会报错 Invalid Date,例如:2022-1-01,2022-01-1,2022-1-1都不行,必须是 2022-01-01

2、在使用 uni-app 开发微信小程序时,分享功能写法应该是这样的:

// vue3 写法
<script setup>
    import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';

    // 分享给好友或群
    onShareAppMessage(() => {
        return {
            title: 'sssss',
            path: '/pages/index/index',
            imageUrl: '/static/default/avatar.png'
        }
    })

    // 分享到朋友圈
    onShareTimeline(() => {
        return {
            title: 'sssss',
            path: '/pages/index/index',
            imageUrl: '/static/default/avatar.png'
        }
    })
</script>

// vue2写法
<script>
    export default {
        // 分享给好友或群
        onShareAppMessage() {
            return {
                title: 'sssss',
                path: '/pages/index/index',
                imageUrl: '/static/default/avatar.png'
            }
        },

        // 分享到朋友圈
        onShareTimeline() {
            return {
                title: 'sssss',
                path: '/pages/index/index',
                imageUrl: '/static/default/avatar.png'
            }
        }
    }
</script>

注意,这段代码要写在页面组件里,也就是在 pages.json 注册过的组件,否则分享配置不生效。

3、在使用 uni-app 开发微信小程序时,不能直接在组件节点上使用 @click ,会无法监听。可以使用 @tap 或者把 @click 放到组件内部的真实节点上:

<!-- 这样无法触发 -->
<template>
    <Item @click="onItemClick(item)" v-for="item in list" :key="item.chatId" :data="item" />
</template>

<!-- 这样可以 -->
<template>
    <Item @tap="onItemClick(item)" v-for="item in list" :key="item.chatId" :data="item" />
</template>

<!-- 这样也可以 -->
<!-- 父组件 -->
<template>
    <Item @click="onItemClick(item)" v-for="item in list" :key="item.chatId" :data="item" />
</template>

<script>
    import Item from './Item'
    const onItemClick = (item) => {
     // your code.
    }
</script>

<!-- 子组件 -->
<template>
    <div class="item" @click="emits('click')"></div>
</template>

<script>
    import { defineEmits } from 'vue'
    const emits = defineEmits(['click']);
</script>

待续...