Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing v-for loop vars from v-runtime-template #9

Closed
hannesaasamets opened this issue Sep 18, 2018 · 4 comments
Closed

Accessing v-for loop vars from v-runtime-template #9

hannesaasamets opened this issue Sep 18, 2018 · 4 comments

Comments

@hannesaasamets
Copy link

Is it possible to use the v-for variables inside the v-runtime-template along the following lines:

<div v-for="row in rows">
  <v-runtime-template :template="'<p>{{row}}</p>'" />
</div>

https://codesandbox.io/s/01l5j73k90

@damey2011
Copy link

it doesnt work for me too

@alexjoverm
Copy link
Owner

alexjoverm commented Oct 8, 2018

I don't think that's possible, since the row variable scope is created by the template as a "temporary" scope, but v-runtime-template has access only to the component scope.

As a workaround you can create a component for the items on the list. In that way, the row would be in the component scope:

<Row :row="row" v-for="row in rows">

@alexjoverm
Copy link
Owner

Or even to place the for loop within the template:

<template>
  <div id="app">
    <v-runtime-template :template="tmplt2" />
  </div>
</template>

<script>
import VRuntimeTemplate from "v-runtime-template";

export default {
  name: "App",
  components: {
    VRuntimeTemplate,
  },
  data() {
    return {
      rows: [1,2,3],
      tmplt2: `
        <div>
          <p v-for="row in rows">{{ row }}</p>
        </div>
      `
	}
  }
}

@alexjoverm
Copy link
Owner

Any option is valid as long as the template access only component instance variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants