1

I'm creating a component dynamically (after a button click), using this commonly followed tutorial. The basic code is:

import Building_Info from './Info_Zone/Building'
var Building_Info_Class = Vue.extend(Building_Info)
var building_info_instance = new Building_Info_Class()
console.log(building_info_instance)
bulding_info_instance.$mount()
place_to_add_component.$el.appendChild(bulding_info_instance.$el)

However, my Building_Info component requires a prop. How can I pass it in? Alternative ways to dynamically creare components are welcome, though ideally they'd support Single File Components.

Note: there are several SO questions about dynamic props, but none I see that speak to this question.

0

1 Answer 1

2

The constructor returned from Vue.extend (i.e., Building_Info_Class) can receive an initialization object, containing the propsData property with initial prop values:

var building_info_instance = new Building_Info_Class({
  propsData: {
    propA: '123',
    propB: true,
  }
})

demo

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

1 Comment

Thank you, that works!

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.