<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Hello Vue</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/* 刷新的时候不显示 */
[v-cloak]{
display: none;
}
.content{
width: 300px;height: 300px;background: #ff6a00;margin: 100px auto;
}
</style>
</head>
<body>
<div id="main">
<ul>
<li v-for="temp in newslist">
{{temp.title}}
</li>
</ul>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var vm = new Vue({
// 要用哪一个div 即V层
el : '#main',
// 数据 即M层
data : {
newslist: [],
},
// 初始化页面函数
mounted(){
this.getList()
},
// 方法 函数
methods : {
getList:function (){
for (var i=0;i<10;i++)
{
var news={}
news.title="我是新闻"+(i+1)
this.newslist.push(news)
}
}
},
})
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Hello Vue</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/* 刷新的时候不显示 */
[v-cloak]{
display: none;
}
.content{
width: 300px;height: 300px;background: #ff6a00;margin: 100px auto;
}
</style>
</head>
<body>
<div id="main">
<ul>
<li v-for="(temp,i) in newslist">
索引---{{i}}---{{temp.title}}
</li>
</ul>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var vm = new Vue({
// 要用哪一个div 即V层
el : '#main',
// 数据 即M层
data : {
newslist: [],
},
// 初始化页面函数
mounted(){
this.getList()
},
// 方法 函数
methods : {
getList:function (){
for (var i=0;i<10;i++)
{
var news={}
news.title="我是新闻"+(i+1)
this.newslist.push(news)
}
}
},
})
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Hello Vue</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/* 刷新的时候不显示 */
[v-cloak]{
display: none;
}
.content{
width: 300px;height: 300px;background: #ff6a00;margin: 100px auto;
}
</style>
</head>
<body>
<div id="main">
<ul>
<li v-for="temp in 100">
{{temp}}
</li>
</ul>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var vm = new Vue({
// 要用哪一个div 即V层
el : '#main',
// 数据 即M层
data : {
},
// 初始化页面函数
mounted(){
},
// 方法 函数
methods : {
},
})
</script>
</body>
</html>
vue教程:https://cn.vuejs.org/v2/guide/
51cto:http://edu.51cto.com/center/course/lesson/index?id=290720