0

I'm using Inertia with VueJS, in the HandleInertiaRequests I have the variable 'foo':

 public function share(Request $request): array
    {
        return [
            'foo' => str()->random(1000)
        ];
    }

Exists a way to update this variable in a VueJS without refreshing the view?

<script setup>
const updateFoo = () => {
// do something here
}
</script>

<template>
{{ $page.props.foo }}

<button @click="updateFoo" type="button">update</button>
</template>

1 Answer 1

0

You can assign the value of foo to a state variable, and then interact with the state variable instead of the props value:

<script setup>
import { ref } from "vue";

const foo = ref(props.foo);

const updateFoo = () => {
// do something here
}
</script>

<template>
{{ foo }}

<button @click="updateFoo" type="button">update</button>
</template>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.