组合式:
javascript
<script setup>
import { ref, onMounted, computed } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
// 响应式数据
const count = ref(0)
const list = ref([])
const inputValue = ref('')
// 计算属性
const filteredList = computed(() => {
return list.value.filter(item => item.includes(inputValue.value))
})
// 生命周期钩子
onMounted(() => {
console.log('组件挂载完成')
})
onLoad(() => {
console.log('页面加载')
})
onShow(() => {
console.log('页面显示')
})
// 方法
const increment = () => {
count.value++
}
const fetchData = async () => {
try {
const res = await uni.request({
url: ''
})
list.value = res.data
} catch (error) {
console.error('请求失败:', error)
}
}
const handleInput = (e) => {
inputValue.value = e.detail.value
}
</script>
<template>
</template>
选项式:
javascript
<template>
</template>
<script setup>
export default{
components: {
},
data() {
return {
};
},
onShow(){
},
methods:{
},
onLoad(){
}
};
</script>
<style scoped>
</style>