Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple html with vue.js not working

A beginner of vue.js and I followed this link: https://www.sitepoint.com/getting-started-with-vue-js/

Almost copy the code into my html.However it just not working.Can someone help me find what is going wrong?
Here are all the codes:

<html>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js">
</script>

<script>

var myModel = {
  name: "Ashley",
  age: 24
};

var myViewModel = new Vue({
  el: '#my_view',
  data: myModel
});

</script>
<div id="my_view">
{{ name }}
</div>
</body>
</html>

The result is just:{{name}}

like image 616
吴环宇 Avatar asked Jan 20 '17 02:01

吴环宇


People also ask

How do I run HTML on Vue?

The simplest way to get started with Vue is to grab the development version script for it and add it to the head tag of your HTML file. Then you can start Vue code inside the HTML file inside of script tags. And have the Vue code connect up with an existing element on your HTML page.

Can you use Vue in HTML?

Embedded Web ComponentsYou can use Vue to build standard Web Components that can be embedded in any HTML page, regardless of how they are rendered.

Is VueJS good for beginners?

Vue. js is going popular day by day because it is very easy to integrate with other projects and libraries. It is very simple to install and use. Even beginners can understand it easily and start building their own user interfaces.

How do I select HTML element in Vue?

We can use querySelector to select an HTML element that returns the first element within the document that matches a specified selector. It can be used to set, obtain, modify, or delete properties of the selected element in Vue.


1 Answers

You need to add the <head> tag and add the script at the end of the file like this:

<html>
<head>
<title></title>
</head>
<body>
<div id="my_view">
{{ name }} {{ age }}
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js"></script>

<script>

var myModel = {
  name: "Ashley",
  age: 24
};

var myViewModel = new Vue({
  el: '#my_view',
  data: myModel
});

</script>

</body>
</html>
like image 143
Wim Mertens Avatar answered Sep 19 '22 18:09

Wim Mertens