I am trying to learn vue . I grabbed a demo project and have much of it working but I am not sure I under stand what this does.
const search = ref("");
const movies= ref([]);
in the template and other places it then accesses the value using search.value. Why use Ref("") ?
CodePudding user response:
ref() allows us to create a "reference" to any value and pass it around without losing reactivity.
The beauty behind that is the fact that you can create reactive properties outside your Vue component. Inside a plain js (or ts) file, just import "ref" from the "vue" package, and then create a reactive property, e.g.
const msg = ref("hello")
For the examples you provided, you're simply initializing the variables with an empty string for search and empty array for movies.
CodePudding user response:
In Vue 3, ref() makes a variable reactive.
