0

I'm trying to quickly learn Vue so I can do some quick hacking for a front end we need for internal use.

I'm following the Vue.js v2 guide specifically the Introduction and I have been implementing the examples one after the other on that page. All work fine when I throw them in an Apache2 folder until I got to app7 which has the first reference to a Vue component.

That example simply doesn't work - the tag <todo-item></todo-item> which is defined by that component simply doesn't show up, the page is empty.

What else do I have to do?

4
  • Did you compile your frontend code? Commented Aug 19, 2019 at 15:14
  • I haven't done anything other than create a one page file containing the HTML and the vue stuff and copying it to a server where Apache can see it. That worked just fine, at least for the first 6 examples. I would have expected that if it was necessary to do anything else for the seventh example, the introduction would have at least mentioned this. Commented Aug 19, 2019 at 17:11
  • If you get stuck with a complex frontend framework, you can always use jQuery, and then switch over to something more testable when you have some refactoring time. Commented Aug 19, 2019 at 20:40
  • It's not the framework that's particularly complex, it's the building infrastructure that's a headache, even when you're trying to do something basic. I'm going to have to find someone to outsource this work to - it's not worth my time to become expert in this stuff. Commented Aug 20, 2019 at 21:25

1 Answer 1

1

Since you are using Vue without a builder (Webpack) and thus obviously without Single-File Components - you have to avoid using custom tags (a.k.a components) in your HTML and instead wrap them inside a template tag like this:

Vue.component('todo-item', {
  props: ['todo'],
  template: '<li>{{ todo.text }}</li>'
})

var app7 = new Vue({
  el: '#app',
  template: '#main', // this is the important part
  data: {
    groceryList: [
      { id: 0, text: 'Vegetables' },
      { id: 1, text: 'Cheese' },
      { id: 2, text: 'Whatever else humans are supposed to eat' }
    ]
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
<div id="app"></div>
<template id="main">
  <ol>
    <!--
      "<todo-item>" is unknown to the browser so you have to put it
      inside "<template>" and then reference the template when
      instantiating your Vue component - otherwise the browser will
      simply ignore it.
    -->
    <todo-item
      v-for="item in groceryList"
      v-bind:todo="item"
      v-bind:key="item.id"
    ></todo-item>
  </ol>
</template>

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

2 Comments

Well, that didn't work either until I finally looked in the browser's debugger and realized that the Vue code has to go after the HTML. Thank you for the info. I understand your solution. So as my next question was in fact going to be about SFC, are you telling me that I can't use those without some preprocessing? If so, can you point me at an example that has the bare minimum necessary for this? The problem with all the examples I've found is that they create all sorts of extra stuff and it's very difficult to figure out what's REQUIRED vs what might be necessary someday!
Yes, you can not use SFC without preprocessing/compiling. You should start with vuejs.org/v2/guide/… which refers to cli.vuejs.org/guide Initially it may feel awkward but soon you will realize that all the stuff actually helps - more or less. The first time you may skip ESLint, Axios, Vuex, Vue-Router and alike - they are not necessary when you are just starting.

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.