【发布时间】:2023-02-12 06:09:30
【问题描述】:
我有一个问题,关于我是否正确地获得了数组 supabase 给出的一个值。
我用这段代码来做到这一点
countries.value = parseInt(countries.value.map(({ aantal }) => aantal));
如果我不将它包装在 parsInt 中,我会得到如下数字:[2000] 所以当我包装它时,我只得到 2000。这是正确的。 我还使用 .toString 对其进行了测试。也有效
我的问题:
这样做是否正确?因为我一开始真的很困惑为什么这个数字被包裹在方括号 []
完整代码
<script setup>
import { ref, onMounted } from "vue";
import { supabase } from "./lib/supabaseClient";
const countries = ref();
async function getCountries() {
const { data } = await supabase.from("count").select("aantal");
countries.value = data;
console.log({ data });
countries.value = parseInt(countries.value.map(({ aantal }) => aantal));
}
async function updateplus() {
countries.value++;
console.log("update", countries.value);
const { data, error } = await supabase
.from("count")
.update({ aantal: countries.value })
.eq("id", 1)
.select();
console.log("update", { data, error });
}
onMounted(() => {
getCountries();
});
const nummber = countries.value;
</script>
<template>
<div>
{{ countries }}
{{ nummber }}
Count
</div>
<div><button @click="updateplus()">Plus 1</button></div>
</template>
【问题讨论】:
标签: javascript arrays vue.js supabase