0

Data Variable

 var data = {
        template:`<div class="box-word-cent">
           <h2>{{ title }}</h2>
           <p>{{ desc }}</p>
         </div>`,

        content:{
           title:'This is Title',
           desc:'This is. Description'
        }
     }

Vue

var vm = new Vue({
    el:'#app',
    data: data
});

Html

<div id="app">
     <div v-html="data.template"></div>
</div>

I try to separate content data from template, but it seems like not work.

any one can help to achieve this conception ?

4
  • Please add language hints so that your source code is displayed with highlighting. Commented May 17, 2017 at 2:39
  • See vuejs.org/v2/guide/syntax.html#Raw-HTML. You cannot use bindings in v-html Commented May 17, 2017 at 2:50
  • my idea is saving vue template to database for easy manipulate Commented May 17, 2017 at 2:52
  • @Phil thanks, i've read it yesterday, v-html cannot render vue template, but how to implement this idea .... it bother me for 2 days... T.T Commented May 17, 2017 at 2:57

1 Answer 1

1

Try

var data = {
    template:`<div class="box-word-cent">
       <h2>{{ title }}</h2>
       <p>{{ desc }}</p>
     </div>`,

    content:{
       title:'This is Title',
       desc:'This is Description'
    }
 }

And

var vm = new Vue({
    el:'#app',
    template: data.template,
    data: data.content
});

And just

<div id="app"></div>

This is an unusual way to write your Vue, however.

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

4 Comments

Looks good though you're missing a comma after data.template ~ jsfiddle.net/n24jo0dc/72
@phil oops! Thank you.
@BertEvans thank you, it's work. do you have any suggestion about saving template with vue syntax to database ?
@AirconChen I've never personally tried saving template to the database.

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.