我想要把 @click="updateid"这个点击事件,调用saveOrUpdateApi这个接口,把当前点击的goodsId传递到这个接口里面,这里的goodsId怎么赋值
以下是打印的Proxy的数据,想取里面的goodsId赋值给上面的接口里
<template>
<view class="u-wrap">
<view class="u-menu-wrap">
<scroll-view scroll-y scroll-with-animation class="u-tab-view menu-scroll-view" :scroll-top="scrollTop">
<view
v-for="(item, index) in tabbar"
:key="index"
class="u-tab-item"
:class="[current == index ? 'u-tab-item-active' : '']"
:data-current="index"
@tap.stop="swichMenu(index)"
>
<text class="u-line-1">{{ item.categoryName }}</text>
</view>
</scroll-view>
<block v-for="(item, index) in tabbar" :key="index">
<scroll-view scroll-y class="right-box" v-if="current == index">
<view class="page-view">
<view class="class-item">
<view class="item-container">
<view class="thumb-box" @click="updateid" v-for="(item1, index1) in item.goods" :key="index1">
<view class="item-menu-name">
<span>{{ item1.goodsName }}</span>
</view>
</view>
</view>
</view>
</view>
</scroll-view>
</block>
</view>
</view>
</template>
<script setup>
import { getCategoryListApi } from '../../api/index.js';
import { ref, getCurrentInstance } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
// 获取组件实例
const instance = getCurrentInstance();
const tabbar = ref([]);
const scrollTop = ref(0);
const current = ref(0);
const menuHeight = ref(0);
const menuItemHeight = ref(0);
const getImg = () => {
return Math.floor(Math.random() * 35);
};
const swichMenu = async (index) => {
if (index == current.value) return;
current.value = index;
// 如果为0,意味着尚未初始化
if (menuHeight.value == 0 || menuItemHeight.value == 0) {
await getElRect('menu-scroll-view', 'menuHeight');
await getElRect('u-tab-item', 'menuItemHeight');
}
// 将菜单菜单活动item垂直居中
scrollTop.value = index * menuItemHeight.value + menuItemHeight.value / 2 - menuHeight.value / 2;
};
const getElRect = (elClass, dataVal) => {
new Promise((resolve, reject) => {
const query = uni.createSelectorQuery().in(instance);
query
.select('.' + elClass)
.fields({ size: true }, (res) => {
// 如果节点尚未生成,res值为null,循环调用执行
if (!res) {
setTimeout(() => {
getElRect(elClass);
}, 10);
return;
}
instance[dataVal] = res.height;
})
.exec();
});
};
//跳转详情
const toDetails = (item) => {
console.log(item);
//在起始页面跳转到details.vue页面并传递参数
uni.navigateTo({
url: '../detail/detail?goods=' + JSON.stringify(item)
});
};
//获取分类数据
const getCategoryList = async () => {
let res = await getCategoryListApi();
if (res && res.code == 200) {
tabbar.value = res.data;
console.log(tabbar.value)
}
};
//引入更新科目api
import { saveOrUpdateApi } from '../../api/user.js';
const updateid = async () => {
let res = await saveOrUpdateApi({
goodsId:
});
};
onLoad(() => {
getCategoryList();
});
</script>