weapp-vue3
创建微信小程序支持hooks(vue3版本)
安装
# npm
npm install @52css/weapp-vue3 --save
# yarn
yarn add @52css/weapp-vue3
# pnpm
pnpm install @52css/weapp-vue3 --save
在小程序中构建

API
Page 页面
import { Page } from '@52css/weapp-vue3'
Page(() => {
})
Component 组件
import { Component } from '@52css/weapp-vue3'
Component(() => {
})
Component({
props: {
type: String
},
setup(props, ctx) {
}
})
定义常量、方法
js
import { Page } from '@52css/weapp-vue3'
Page(() => {
const text = 'hello weapp vue3'
const handleClick = () => {
console.log('text', text)
}
return { text, handleClick }
})
wxml
<view bind:tap="handleClick">
text:{{text}}
</view>
效果

ref
js
import { Page, ref } from '@52css/weapp-vue3'
Page(() => {
const count = ref(0)
return { count }
})
wxml
<view>
count: {{count}}
</view>
效果

reactive
js
import { Page, reactive, toRefs } from '@52css/weapp-vue3'
Page(() => {
const state = reactive({loading: false})
return { ...toRefs(state) }
})
wxml
computed
import { Page, ref, computed } from '@52css/weapp-vue3'
Page(() => {
const count = ref(0)
const doubleCount = computed(() => count.value * 2)
return { count, doubleCount }
})
watch
import { Page, ref, watch } from '@52css/weapp-vue3'
Page(() => {
const count = ref(0)
const handleClick = () => {
count.value ++
}
watch(count, (newVal, oldVal) => {
console.log('newVal', newVal, oldVal)
})
return { count, handleClick }
})
生命周期
TODO