0

I'm learning Vue.js framework and I'm making some tries in order to handle this JavaScript framework.

My example is very simple, but I don't overcome to display data {} according to .html and .js files.

This is my .html file :

<!DOCTYPE html>
<html>
<head>
    <title>Test de Vue.js</title>
    <script src="test.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
</head>
<body>

    <div id='test'>
        <p>{{ texte }}</p>
    </div>

</body>
</html>

And my .js file located in the same directory :

var vm = new Vue ({
    el : '#test',
    data : {
        texte : 'Ceci est un premier test en Vue.js'
    }
});

But, I don't know why my browser displays this :

enter image description here

Thank you so much

5
  • @Derek Yes you can see script src="test.js"></script> in my HTML file Commented Jul 9, 2018 at 8:33
  • 2
    Move your script to the bottom of the page. test.js is running before the HTML is rendered. And also the scripts are in reverse order. Commented Jul 9, 2018 at 8:33
  • @RolandStarke Oh ok ! I have to load CDN in first time, then my .js script Commented Jul 9, 2018 at 8:34
  • @Bert Thank you very much ! It's a very newbie issue .. Commented Jul 9, 2018 at 8:36
  • No worries, we are all new at some point :) Commented Jul 9, 2018 at 8:37

1 Answer 1

2

Your scripts are in incorrect order. You have to include Vue.js first, then your script as second, because your script references Vue object, which is defined in vue.js.

Also, while vue.js can be included in <head>, your Vue model definition should go into the <body> tag, after the target element, otherwise, it will not work.

<head>
    ...
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
</head>
<body>
    <div id="test">...</div>
    <script src="test.js"></script>
</body>
Sign up to request clarification or add additional context in comments.

2 Comments

Ok ! Right it works now ! It's really a newbie issue .. I'm sorry :/ Thank you !
I have to move my .js script outside of HTML header ;)

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.