How to render the list in vue.js?












1














I'm trying to render the list with vue.js. The data has come from api call.



List rendering is ok, until I try to add data-feature_id="@{{searched_feature.id}}" in li tag.
When I add it, I got an error:




[Vue warn]: Error compiling template:......




<div class="search_feature_select">
<ul>
<li v-for="searched_feature in searched_features" data-feature_id="@{{searched_feature.id}}" @click="add_to_features_list">
@{{searched_feature.name}}
</li>
</ul>
</div>


How can I put searched_feature.id in data-feature_id attribute?










share|improve this question





























    1














    I'm trying to render the list with vue.js. The data has come from api call.



    List rendering is ok, until I try to add data-feature_id="@{{searched_feature.id}}" in li tag.
    When I add it, I got an error:




    [Vue warn]: Error compiling template:......




    <div class="search_feature_select">
    <ul>
    <li v-for="searched_feature in searched_features" data-feature_id="@{{searched_feature.id}}" @click="add_to_features_list">
    @{{searched_feature.name}}
    </li>
    </ul>
    </div>


    How can I put searched_feature.id in data-feature_id attribute?










    share|improve this question



























      1












      1








      1







      I'm trying to render the list with vue.js. The data has come from api call.



      List rendering is ok, until I try to add data-feature_id="@{{searched_feature.id}}" in li tag.
      When I add it, I got an error:




      [Vue warn]: Error compiling template:......




      <div class="search_feature_select">
      <ul>
      <li v-for="searched_feature in searched_features" data-feature_id="@{{searched_feature.id}}" @click="add_to_features_list">
      @{{searched_feature.name}}
      </li>
      </ul>
      </div>


      How can I put searched_feature.id in data-feature_id attribute?










      share|improve this question















      I'm trying to render the list with vue.js. The data has come from api call.



      List rendering is ok, until I try to add data-feature_id="@{{searched_feature.id}}" in li tag.
      When I add it, I got an error:




      [Vue warn]: Error compiling template:......




      <div class="search_feature_select">
      <ul>
      <li v-for="searched_feature in searched_features" data-feature_id="@{{searched_feature.id}}" @click="add_to_features_list">
      @{{searched_feature.name}}
      </li>
      </ul>
      </div>


      How can I put searched_feature.id in data-feature_id attribute?







      javascript vue.js






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 28 '18 at 10:39









      Styx

      3,27642334




      3,27642334










      asked Dec 28 '18 at 9:32









      Mg Mg TintMg Mg Tint

      112




      112
























          4 Answers
          4






          active

          oldest

          votes


















          2














          You need to add : before the attribute



          <div class="search_feature_select">
          <ul>
          <li v-for="searched_feature in searched_features" :data-feature_id="searched_feature.id" @click="add_to_features_list">
          {{searched_feature.name}}
          </li>
          </ul>
          </div>





          share|improve this answer































            0














            Add 'v-bind:' prefix of shorthand ':' before attribute to bind dynamic data.



            <div class="search_feature_select">
            <ul>
            <li v-for="searched_feature in searched_features"
            :data-feature_id="searched_feature.id"
            @click="add_to_features_list">
            {{searched_feature.name}}
            </li>
            </ul>
            </div>


            See more https://vuejs.org/v2/api/#v-bind






            share|improve this answer





























              0














              https://vuejs.org/v2/guide/list.html coughcough*






              var app = new Vue({
              el: "#app",
              data: {
              searched_features: [
              {
              id: 1,
              name: "One"
              },
              {
              id: 2,
              name: "Two"
              },
              {
              id: 3,
              name: "Three"
              }
              ]
              },
              methods: {
              add_to_features_list(){}
              }
              })

              <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
              <div id="app">
              <div class="search_feature_select">
              <ul>
              <li v-for="searched_feature in searched_features" :data-feature_id="searched_feature.id" @click="add_to_features_list">
              @{{ searched_feature.name }}
              </li>
              </ul>
              </div>
              </div>








              share|improve this answer





























                0














                if you wish to add the '@' in front of the data-feature_id attribute:



                <div class="search_feature_select">
                <ul>
                <li v-for="searched_feature in searched_features" :data-feature_id="'@' + searched_feature.id" @click="add_to_features_list">
                {{searched_feature.name}}
                </li>
                </ul>
                </div>





                share|improve this answer





















                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53956330%2fhow-to-render-the-list-in-vue-js%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  2














                  You need to add : before the attribute



                  <div class="search_feature_select">
                  <ul>
                  <li v-for="searched_feature in searched_features" :data-feature_id="searched_feature.id" @click="add_to_features_list">
                  {{searched_feature.name}}
                  </li>
                  </ul>
                  </div>





                  share|improve this answer




























                    2














                    You need to add : before the attribute



                    <div class="search_feature_select">
                    <ul>
                    <li v-for="searched_feature in searched_features" :data-feature_id="searched_feature.id" @click="add_to_features_list">
                    {{searched_feature.name}}
                    </li>
                    </ul>
                    </div>





                    share|improve this answer


























                      2












                      2








                      2






                      You need to add : before the attribute



                      <div class="search_feature_select">
                      <ul>
                      <li v-for="searched_feature in searched_features" :data-feature_id="searched_feature.id" @click="add_to_features_list">
                      {{searched_feature.name}}
                      </li>
                      </ul>
                      </div>





                      share|improve this answer














                      You need to add : before the attribute



                      <div class="search_feature_select">
                      <ul>
                      <li v-for="searched_feature in searched_features" :data-feature_id="searched_feature.id" @click="add_to_features_list">
                      {{searched_feature.name}}
                      </li>
                      </ul>
                      </div>






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Dec 28 '18 at 9:53

























                      answered Dec 28 '18 at 9:41









                      MahmoudMahmoud

                      608717




                      608717

























                          0














                          Add 'v-bind:' prefix of shorthand ':' before attribute to bind dynamic data.



                          <div class="search_feature_select">
                          <ul>
                          <li v-for="searched_feature in searched_features"
                          :data-feature_id="searched_feature.id"
                          @click="add_to_features_list">
                          {{searched_feature.name}}
                          </li>
                          </ul>
                          </div>


                          See more https://vuejs.org/v2/api/#v-bind






                          share|improve this answer


























                            0














                            Add 'v-bind:' prefix of shorthand ':' before attribute to bind dynamic data.



                            <div class="search_feature_select">
                            <ul>
                            <li v-for="searched_feature in searched_features"
                            :data-feature_id="searched_feature.id"
                            @click="add_to_features_list">
                            {{searched_feature.name}}
                            </li>
                            </ul>
                            </div>


                            See more https://vuejs.org/v2/api/#v-bind






                            share|improve this answer
























                              0












                              0








                              0






                              Add 'v-bind:' prefix of shorthand ':' before attribute to bind dynamic data.



                              <div class="search_feature_select">
                              <ul>
                              <li v-for="searched_feature in searched_features"
                              :data-feature_id="searched_feature.id"
                              @click="add_to_features_list">
                              {{searched_feature.name}}
                              </li>
                              </ul>
                              </div>


                              See more https://vuejs.org/v2/api/#v-bind






                              share|improve this answer












                              Add 'v-bind:' prefix of shorthand ':' before attribute to bind dynamic data.



                              <div class="search_feature_select">
                              <ul>
                              <li v-for="searched_feature in searched_features"
                              :data-feature_id="searched_feature.id"
                              @click="add_to_features_list">
                              {{searched_feature.name}}
                              </li>
                              </ul>
                              </div>


                              See more https://vuejs.org/v2/api/#v-bind







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Dec 28 '18 at 9:52









                              Cong NguyenCong Nguyen

                              35728




                              35728























                                  0














                                  https://vuejs.org/v2/guide/list.html coughcough*






                                  var app = new Vue({
                                  el: "#app",
                                  data: {
                                  searched_features: [
                                  {
                                  id: 1,
                                  name: "One"
                                  },
                                  {
                                  id: 2,
                                  name: "Two"
                                  },
                                  {
                                  id: 3,
                                  name: "Three"
                                  }
                                  ]
                                  },
                                  methods: {
                                  add_to_features_list(){}
                                  }
                                  })

                                  <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
                                  <div id="app">
                                  <div class="search_feature_select">
                                  <ul>
                                  <li v-for="searched_feature in searched_features" :data-feature_id="searched_feature.id" @click="add_to_features_list">
                                  @{{ searched_feature.name }}
                                  </li>
                                  </ul>
                                  </div>
                                  </div>








                                  share|improve this answer


























                                    0














                                    https://vuejs.org/v2/guide/list.html coughcough*






                                    var app = new Vue({
                                    el: "#app",
                                    data: {
                                    searched_features: [
                                    {
                                    id: 1,
                                    name: "One"
                                    },
                                    {
                                    id: 2,
                                    name: "Two"
                                    },
                                    {
                                    id: 3,
                                    name: "Three"
                                    }
                                    ]
                                    },
                                    methods: {
                                    add_to_features_list(){}
                                    }
                                    })

                                    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
                                    <div id="app">
                                    <div class="search_feature_select">
                                    <ul>
                                    <li v-for="searched_feature in searched_features" :data-feature_id="searched_feature.id" @click="add_to_features_list">
                                    @{{ searched_feature.name }}
                                    </li>
                                    </ul>
                                    </div>
                                    </div>








                                    share|improve this answer
























                                      0












                                      0








                                      0






                                      https://vuejs.org/v2/guide/list.html coughcough*






                                      var app = new Vue({
                                      el: "#app",
                                      data: {
                                      searched_features: [
                                      {
                                      id: 1,
                                      name: "One"
                                      },
                                      {
                                      id: 2,
                                      name: "Two"
                                      },
                                      {
                                      id: 3,
                                      name: "Three"
                                      }
                                      ]
                                      },
                                      methods: {
                                      add_to_features_list(){}
                                      }
                                      })

                                      <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
                                      <div id="app">
                                      <div class="search_feature_select">
                                      <ul>
                                      <li v-for="searched_feature in searched_features" :data-feature_id="searched_feature.id" @click="add_to_features_list">
                                      @{{ searched_feature.name }}
                                      </li>
                                      </ul>
                                      </div>
                                      </div>








                                      share|improve this answer












                                      https://vuejs.org/v2/guide/list.html coughcough*






                                      var app = new Vue({
                                      el: "#app",
                                      data: {
                                      searched_features: [
                                      {
                                      id: 1,
                                      name: "One"
                                      },
                                      {
                                      id: 2,
                                      name: "Two"
                                      },
                                      {
                                      id: 3,
                                      name: "Three"
                                      }
                                      ]
                                      },
                                      methods: {
                                      add_to_features_list(){}
                                      }
                                      })

                                      <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
                                      <div id="app">
                                      <div class="search_feature_select">
                                      <ul>
                                      <li v-for="searched_feature in searched_features" :data-feature_id="searched_feature.id" @click="add_to_features_list">
                                      @{{ searched_feature.name }}
                                      </li>
                                      </ul>
                                      </div>
                                      </div>








                                      var app = new Vue({
                                      el: "#app",
                                      data: {
                                      searched_features: [
                                      {
                                      id: 1,
                                      name: "One"
                                      },
                                      {
                                      id: 2,
                                      name: "Two"
                                      },
                                      {
                                      id: 3,
                                      name: "Three"
                                      }
                                      ]
                                      },
                                      methods: {
                                      add_to_features_list(){}
                                      }
                                      })

                                      <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
                                      <div id="app">
                                      <div class="search_feature_select">
                                      <ul>
                                      <li v-for="searched_feature in searched_features" :data-feature_id="searched_feature.id" @click="add_to_features_list">
                                      @{{ searched_feature.name }}
                                      </li>
                                      </ul>
                                      </div>
                                      </div>





                                      var app = new Vue({
                                      el: "#app",
                                      data: {
                                      searched_features: [
                                      {
                                      id: 1,
                                      name: "One"
                                      },
                                      {
                                      id: 2,
                                      name: "Two"
                                      },
                                      {
                                      id: 3,
                                      name: "Three"
                                      }
                                      ]
                                      },
                                      methods: {
                                      add_to_features_list(){}
                                      }
                                      })

                                      <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
                                      <div id="app">
                                      <div class="search_feature_select">
                                      <ul>
                                      <li v-for="searched_feature in searched_features" :data-feature_id="searched_feature.id" @click="add_to_features_list">
                                      @{{ searched_feature.name }}
                                      </li>
                                      </ul>
                                      </div>
                                      </div>






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Dec 28 '18 at 9:53









                                      AnugaAnuga

                                      926718




                                      926718























                                          0














                                          if you wish to add the '@' in front of the data-feature_id attribute:



                                          <div class="search_feature_select">
                                          <ul>
                                          <li v-for="searched_feature in searched_features" :data-feature_id="'@' + searched_feature.id" @click="add_to_features_list">
                                          {{searched_feature.name}}
                                          </li>
                                          </ul>
                                          </div>





                                          share|improve this answer


























                                            0














                                            if you wish to add the '@' in front of the data-feature_id attribute:



                                            <div class="search_feature_select">
                                            <ul>
                                            <li v-for="searched_feature in searched_features" :data-feature_id="'@' + searched_feature.id" @click="add_to_features_list">
                                            {{searched_feature.name}}
                                            </li>
                                            </ul>
                                            </div>





                                            share|improve this answer
























                                              0












                                              0








                                              0






                                              if you wish to add the '@' in front of the data-feature_id attribute:



                                              <div class="search_feature_select">
                                              <ul>
                                              <li v-for="searched_feature in searched_features" :data-feature_id="'@' + searched_feature.id" @click="add_to_features_list">
                                              {{searched_feature.name}}
                                              </li>
                                              </ul>
                                              </div>





                                              share|improve this answer












                                              if you wish to add the '@' in front of the data-feature_id attribute:



                                              <div class="search_feature_select">
                                              <ul>
                                              <li v-for="searched_feature in searched_features" :data-feature_id="'@' + searched_feature.id" @click="add_to_features_list">
                                              {{searched_feature.name}}
                                              </li>
                                              </ul>
                                              </div>






                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Dec 28 '18 at 9:56









                                              Tang YunTang Yun

                                              898




                                              898






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Stack Overflow!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.





                                                  Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                  Please pay close attention to the following guidance:


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53956330%2fhow-to-render-the-list-in-vue-js%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  Monofisismo

                                                  Angular Downloading a file using contenturl with Basic Authentication

                                                  Olmecas