javascript - Vue Router params not updating in page - Stack Overflow

Hello I have some conditional logic in my view based on the current pagein setup I haveconst curVidTy

Hello I have some conditional logic in my view based on the current page

in setup I have

const curVidType = ref(route.params.videoTopic);

I return it and then print out like

<h1>Wele to  {{ curVidType }} videos</h1>

However it only works if I refresh. If I browse to a new page it stays the old one even though the browser url changes. after refresh it updates. Thanks so much for any help

Hello I have some conditional logic in my view based on the current page

in setup I have

const curVidType = ref(route.params.videoTopic);

I return it and then print out like

<h1>Wele to  {{ curVidType }} videos</h1>

However it only works if I refresh. If I browse to a new page it stays the old one even though the browser url changes. after refresh it updates. Thanks so much for any help

Share Improve this question asked Apr 29, 2021 at 18:18 atx123natx123n 532 silver badges7 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

Try adding :key to your Component to make sure it updates when param changes:

<your-ponent :key="$route.params.videoTopic"></your-ponent>

You're initializing the variable as a const, which means it does it once and then doesn't set it. If you change curVidType to a puted value, you can have it react to changes in the router params.

puted: {
  curVidType() {
    return route.params.videoTopics
  }
}

This will have the value of curVidType set to change when videoTopics does

EDIT:

Having read the ments and looked at the ments and read some of the documentations, ref() will create a reactive object but I'm not sure it's reacting to the original object. But it looks like the toRef() function can create that bridge.

const curVidType = toRef(route.params, 'videoTopics')

Should allow for curVidType.value to also reflect changes to to route.params.videoTopics

Would be nice if you could share some more code with us in order to help you. This should just work fine

<template>
{{ curVidType }}
</template>

<script>
import { useRoute } from 'vue-router';

export default {
    setup() {
        const { params } = useRoute();
        const curVidType = params.videoTopic

        return {
            curVidType,
        };
    },
};
</script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742369242a4430925.html

相关推荐

  • javascript - Vue Router params not updating in page - Stack Overflow

    Hello I have some conditional logic in my view based on the current pagein setup I haveconst curVidTy

    14小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信