0

I am trying to follow this tutorial and copied the code. The only thing I changed is the location of index.js, what should not be the issue, as the hello world tutorial worked fine. The consoles outputs the following:

[Vue warn]: Property or method "seen" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.(found in <Root>)

So my questions if, if there is anything wrong with this code from the index.js file:

var app = new Vue({
  el: '#app',
  data: {
    seen: true
  }
})

or is there something wrong with the html file (inserted into a markdown file, thus the title part)

---
title: vue
---
<html>
    <head>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    </head>
    <body>

        <div id="app">
            <span v-if="seen">Now you see me</span>
        </div>

        <script src="vue/index.js"></script>
    </body>
</html>

It is probably a simple mistake, but I have been fiddling around for two hours. It would be great if someone could help me out.

1
  • 3
    please provide part that raises this issue Commented Dec 2, 2020 at 18:58

2 Answers 2

2

First, we don't write data like this but like this data(){return { seen:true };}

And this code works:

<template>
  <div id="app">
    <span v-if="seen">Now you see me</span>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      seen: true,
    };
  },
};
</script>

<style>
</style>

Something cool with Vuejs is that HTML JS and CSS part is on the same page. And for the HTML part, it's just an <template> and inside add direct the <div> without <body>

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

1 Comment

--- title: vue --- <html> <head> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <template> <div id="app"> <span v-if="seen">Now you see me</span> </div> </template> <script type="text/javascript"> export default { name: "App", data() { return { seen: true, }; }, }; </script> <style> </style> </html> This code produces the error vue:143 Uncaught SyntaxError: Unexpected token 'export'.
1

If you're using CDN your code should be like :

<html>

<head>
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<div id="app">
  <span v-if="seen">Now you see me</span>

</div>
<script type="text/javascript">
  new Vue({
    el: "#app",
    data() {
      return {
        seen: true,
      };
    },
  });
</script>
<style>

</style>

</html>

you define data as a function that returns object.

6 Comments

Your example works, but it still does not work with an external js file. I copied new Vue({ el: "#app", data() { return { seen: true, }; }, }); into index.js, which still outputs the above mentioned error
try out <script src="./vue/index.js"></script> or <script src="/vue/index.js"></script>
The path is right I guess. Otherwise the console outputs GET http://localhost/vue/index.js net::ERR_ABORTED 404 (Not Found)
It finally worked. I dont know why, but my browser did not load the latest index.js file. The web inspector was still showing my old "hello world" example. I changed the browser and the recent index.js file loaded! Thanks!
you're welcome, which browsers did you used?
|

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.