Vue: Setting Dynamic path to template's src property

Created on 31 Jan 2018  ·  6Comments  ·  Source: vuejs/vue

What problem does this feature solve?

I am not sure whether there is an good alternative to this problem but yes if this does exist, it would help users to dynamically set path to src of template. I need to have one .ts file(src in script tag) and multiple html files in one template tag(one at a time as per request).
Users can just set dynamic path to src when needed if binding starts to work there.

What does the proposed API look like?

example should look like this.

vuehtml

As seen, src is binded and would change path by setting it in same component or can be passed by parent component in a props way. So now the path becomes dynamic and you don't have to write same script everytime for different html to work with.

Most helpful comment

Why don't you put your script in a Js file and then use it in several components?

<script src="my-common-script.js"/>

All 6 comments

Well, that can't work - SFCs are processed at build time, but the javascript code of the component is run later, at runtime, in the browser.

Can't be even considered as Enhancement for future ? And what could be a possible way to achieve it if this can't be possible ?

Can't be even considered as Enhancement for future ?

No, this is simply logically impossible.

And what could be a possible way to achieve it

I'm not sure in what context you want to do something like this so I'm not sure if something similar can be stitched together. That would be a question for forum.vuejs.org - so I suggest you start a discussion topic there with more information about your requirements.

As a feature, this won't happen - and if it would, it would happen in vue-loader, not vue, so this would be thewrong repository anyways.

Why don't you put your script in a Js file and then use it in several components?

<script src="my-common-script.js"/>

@Akryum Because that will just make a lot of .vue files which I really don't want.

But you are ok with a lot of html files? :smile:

Was this page helpful?
0 / 5 - 0 ratings