admin管理员组文章数量:1345728
I'm trying to start using Tanstack
and am having problems passing variables into mutation functions.
In the following, "newTodo" is returning undefined.
<script setup>
import axios from "axios";
import {
useMutation
} from '@tanstack/vue-query'
const {
isPending,
isError,
error,
isSuccess,
mutate
} = useMutation({
mutationFn: (newTodo) => {
console.log(newTodo)
},
})
function addTodo() {
mutate({
id: new Date(),
title: 'Do Laundry'
});
}
</script>
<template>
<span v-if="isPending">Adding todo...</span>
<span v-else-if="isError">An error occurred: {{ error.message }}</span>
<span v-else-if="isSuccess">Todo added!</span>
<button @click="addTodo">Create Todo</button>
</template>
I copied this directly from their documentation, other than the newTodo that I'm console logging to make my point. I have the latest Vue and the latest tanstack.
Others indicate this works fine for them.
"@tanstack/vue-query": "^5.71.5",
"axios": "^1.7.9",
"pinia": "^2.1.7",
"pusher-js": "^8.4.0-rc2",
"vue": "^3.4.21",
Seems like it must have something to do w/ a configuration but there's no config needed for tanstack other than adding it to the app, which I've done.
No idea why they won't pass through.
本文标签: javascriptWhy aren39t my variables passed to my Tanstack mutation functionStack Overflow
版权声明:本文标题:javascript - Why aren't my variables passed to my Tanstack mutation function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743814359a2543640.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论