1

I have searched this issue and tried all the things but did not work for me. I am using Vue 3 ref and it needs to be updated after calling the Axios with the response but it is not getting updated here is some piece of code.

Here invite_link is an object

const props = defineProps({
   'workplace': Object 
  });

// Also tried const workplace = props.workplace;

const workplace = ref(props.workplace);
axios.post(url).then(res=>{
  workplace.value.invite_link = res.data.workplace.invite_link
});
 

and in the template I am using v-show="workplace.invite_link" that needs to be shown after Axios ran successfully. I have also check Vue devtools and it still shows the old workplace object

1

1 Answer 1

4
const workplace = ref(props.workplace);

It is important to understand that setup is executed only once in component lifecycle. The code above creates a ref and INITIALISE it with the current value of props.workplace. The value of such ref will never ever change.

If you want to create a ref which value will update whenever props.workplace updates (which is almost always what you want), do this:

const { workplace } = toRefs(props);

or

const workplace = toRef(props, 'workplace');

Docs

Sign up to request clarification or add additional context in comments.

1 Comment

I have already tired toRef but when I tried to change the value of workplace after axios it does not update

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.