两次撞击触发器观察效应
我将VUEJS 3与组合API一起使用。
一个带有参数的组件看起来像这样:https://webiste/eaccem/1/4/2022
,其中1 = id,4 =一个月。
在该组件中,我有2个链接可以转到下个月或上个月:
<router-link
:to="{ name: 'comptes', params: {id: 1, month: nextmonth, year: nextyear } }"
class="text-sky-600">next month</router-link>
nexmonth
和nextyear
是计算出的属性,这些属性是...如果需要)。
我在每次路由参数更改时运行Axios
调用:
<script setup>
import { ref, onMounted, computed, watchEffect } from "vue"
const getaccounts = async () => {
// axios get results and put into ref ; cut for clarity
}
onMounted(() => {
getaccounts()
watchEffect(() => getaccounts() )
});
显然,第一次加载页面时,getAccounts()方法被调用两次。我该如何改变?
I'm using vuejs 3 with the composition API.
One component with params looks like this: https://webiste/accounts/1/4/2022
, where 1 = id, 4 = month.
In that component, I have 2 links to go to the next month or previous month:
<router-link
:to="{ name: 'comptes', params: {id: 1, month: nextmonth, year: nextyear } }"
class="text-sky-600">next month</router-link>
nexmonth
and nextyear
are computed properties that go ... to the next month (and year if need be).
I run the axios
call each time the route params change:
<script setup>
import { ref, onMounted, computed, watchEffect } from "vue"
const getaccounts = async () => {
// axios get results and put into ref ; cut for clarity
}
onMounted(() => {
getaccounts()
watchEffect(() => getaccounts() )
});
Obviously, the first time the page is loaded, the getAccounts() method gets called twice. How can I change that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论