user8430652
user8430652

Reputation: 21

How to add a property to reactive object VueJS 3?

export default {
  setup() {
    const imageUrl = ref("");
    const title = ref("");
    const description = ref("");
    var source = "Global";

    const form = reactive({
      title: "",
      description: "",
      // src: source,
    });
    //...
  }
}

How do I add src: "source" (a new property) to form (the reactive object)? Like how we append on ref.

Upvotes: 2

Views: 3669

Answers (1)

tony19
tony19

Reputation: 138696

You can assign the field directly via form.src = source. For example, you could have a function that does this:

const addSourceToForm = () => form.src = source

And you can call that function later, e.g., from a button click:

<button @click="addSourceToForm">Add source</button>

demo

Upvotes: 3

Related Questions