|
步骤
1
:
v-for 循环语句
步骤
2
:
index用法
步骤
3
:
纯数字遍历
首选准备一个数组 var data = [ {name:"盖伦",hp:341}, {name:"提莫",hp:225}, {name:"安妮",hp:427}, {name:"死歌",hp:893} ];
然后在构建Vue的时候把这个数组作为参数传递进去: data: { heros:data }
最后在视图上,通过v-for 遍历这个数组。 <tr v-for="hero in heros"> <td>{{hero.name}}</td> <td>{{hero.hp}}</td> </tr>
");
window.frames["iframe_show7798"].document.write(decodeHtml($("textarea#stepcodeTextarea7798").val()));
window.frames["iframe_show7798"].document.close();
$(window.frames["iframe_show7798"]).load(function(){
$("#iframe_show7798").height($("#iframe_show7798").contents().find("body").height()+showittryitheight);
});
$("#iframe_show7798").height($("#iframe_show7798").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/vue.min.js"></script>
<style>
table tr td{
border:1px solid gray;
}
table{
border-collapse:collapse;
width:300px;
}
tr.firstLine{
background-color: lightGray;
}
</style>
<div id="div1">
<table align="center" >
<tr class="firstLine">
<td>name</td>
<td>hp</td>
</tr>
<tr v-for="hero in heros">
<td>{{hero.name}}</td>
<td>{{hero.hp}}</td>
</tr>
</table>
</div>
<script>
var data = [
{name:"盖伦",hp:341},
{name:"提莫",hp:225},
{name:"安妮",hp:427},
{name:"死歌",hp:893}
];
new Vue({
el: '#div1',
data: {
heros:data
}
})
</script>
<script src="http://127.0.0.1/study/vue.min.js"></script>
<style>
table tr td{
border:1px solid gray;
}
table{
border-collapse:collapse;
width:300px;
}
tr.firstLine{
background-color: lightGray;
}
</style>
<div id="div1">
<table align="center" >
<tr class="firstLine">
<td>name</td>
<td>hp</td>
</tr>
<tr v-for="hero in heros">
<td>{{hero.name}}</td>
<td>{{hero.hp}}</td>
</tr>
</table>
</div>
<script>
var data = [
{name:"盖伦",hp:341},
{name:"提莫",hp:225},
{name:"安妮",hp:427},
{name:"死歌",hp:893}
];
new Vue({
el: '#div1',
data: {
heros:data
}
})
</script>
");
window.frames["iframe7798"].document.write(decodeHtml(code7798));
window.frames["iframe7798"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7798"]).load(function(){
$("#iframe7798").height($("#iframe7798").contents().find("body").height()+showittryitheight);
});
$("#iframe7798").height($("#iframe7798").contents().find("body").height()+showittryitheight);
alreadyWriteCode7798 = code7798;
$("#rendering7798").hide();
$("#rendered7798").show();
}
var tRereshRetry2DemoPanel7798 = setInterval(rereshRetry2DemoPanel7798,1000);
var binded7798 = false;
$("textarea#stepcodeTextarea7798").keyup(function(){
if(!binded7798){
$(window).bind('beforeunload',function(){
binded7798 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code7798 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code7798!=newCode){
// window.frames["iframe7798"].document.write("
");
// window.frames["iframe7798"].document.write(decodeHtml($("textarea#stepcodeTextarea7798").val()));
// window.frames["iframe7798"].document.close();
// $(window.frames["iframe7798"]).load(function(){
// $("#iframe7798").height($("#iframe7798").contents().find("body").height()+showittryitheight);
// });
// code7798 = newCode;
// }
});
$(".tryButton7798").click(function(){
$("#tryDiv7798").show();
$("#stepcodeTextarea7798").focus();
$("#stepcodeTextarea7798").height(200);
$("#iframe7798").height(0);
window.frames["iframe7798"].document.write("
");
window.frames["iframe7798"].document.write(decodeHtml($("textarea#stepcodeTextarea7798").val()));
window.frames["iframe7798"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7798"]).load(function(){
$("#iframe7798").height($("#iframe7798").contents().find("body").height()+showittryitheight);
});
$("#iframe7798").height($("#iframe7798").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor7798.focus();
editor7798.setSize(null, "250");
$("#rendering7798").hide();
$("#rendered7798").hide();
});
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
};
var editor7798 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea7798"), {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
mode:"text/html",
theme:"eclipse",
selectionPointer: true,
lineWrapping: true,
extraKeys: {
"Alt-/": "autocomplete",
"Ctrl-F": "findPersistent",
"F8": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
editor7798.on("change",function(doc){
if(!binded7798){
$(window).bind('beforeunload',function(){
binded7798 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code7798 = newCode;
$("textarea#stepcodeTextarea7798").val(newCode);
if(alreadyWriteCode7798!=code7798){
lastModifedTime7798 = new Date().getTime();
$("#rendering7798").show();
$("#rendered7798").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor7798 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor7798.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv7798").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
通过如下方式可以获取遍历下标 <tr v-for="hero,index in heros">
");
window.frames["iframe_show7799"].document.write(decodeHtml($("textarea#stepcodeTextarea7799").val()));
window.frames["iframe_show7799"].document.close();
$(window.frames["iframe_show7799"]).load(function(){
$("#iframe_show7799").height($("#iframe_show7799").contents().find("body").height()+showittryitheight);
});
$("#iframe_show7799").height($("#iframe_show7799").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/vue.min.js"></script>
<style>
table tr td{
border:1px solid gray;
}
table{
border-collapse:collapse;
width:300px;
}
tr.firstLine{
background-color: lightGray;
}
</style>
<div id="div1">
<table align="center" >
<tr class="firstLine">
<td>number</td>
<td>name</td>
<td>hp</td>
</tr>
<tr v-for="hero,index in heros">
<td>{{index+1}}</td>
<td>{{hero.name}}</td>
<td>{{hero.hp}}</td>
</tr>
</table>
</div>
<script>
var data = [
{name:"盖伦",hp:341},
{name:"提莫",hp:225},
{name:"安妮",hp:427},
{name:"死歌",hp:893}
];
new Vue({
el: '#div1',
data: {
heros:data
}
})
</script>
<script src="http://127.0.0.1/study/vue.min.js"></script>
<style>
table tr td{
border:1px solid gray;
}
table{
border-collapse:collapse;
width:300px;
}
tr.firstLine{
background-color: lightGray;
}
</style>
<div id="div1">
<table align="center" >
<tr class="firstLine">
<td>number</td>
<td>name</td>
<td>hp</td>
</tr>
<tr v-for="hero,index in heros">
<td>{{index+1}}</td>
<td>{{hero.name}}</td>
<td>{{hero.hp}}</td>
</tr>
</table>
</div>
<script>
var data = [
{name:"盖伦",hp:341},
{name:"提莫",hp:225},
{name:"安妮",hp:427},
{name:"死歌",hp:893}
];
new Vue({
el: '#div1',
data: {
heros:data
}
})
</script>
");
window.frames["iframe7799"].document.write(decodeHtml(code7799));
window.frames["iframe7799"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7799"]).load(function(){
$("#iframe7799").height($("#iframe7799").contents().find("body").height()+showittryitheight);
});
$("#iframe7799").height($("#iframe7799").contents().find("body").height()+showittryitheight);
alreadyWriteCode7799 = code7799;
$("#rendering7799").hide();
$("#rendered7799").show();
}
var tRereshRetry2DemoPanel7799 = setInterval(rereshRetry2DemoPanel7799,1000);
var binded7799 = false;
$("textarea#stepcodeTextarea7799").keyup(function(){
if(!binded7799){
$(window).bind('beforeunload',function(){
binded7799 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code7799 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code7799!=newCode){
// window.frames["iframe7799"].document.write("
");
// window.frames["iframe7799"].document.write(decodeHtml($("textarea#stepcodeTextarea7799").val()));
// window.frames["iframe7799"].document.close();
// $(window.frames["iframe7799"]).load(function(){
// $("#iframe7799").height($("#iframe7799").contents().find("body").height()+showittryitheight);
// });
// code7799 = newCode;
// }
});
$(".tryButton7799").click(function(){
$("#tryDiv7799").show();
$("#stepcodeTextarea7799").focus();
$("#stepcodeTextarea7799").height(200);
$("#iframe7799").height(0);
window.frames["iframe7799"].document.write("
");
window.frames["iframe7799"].document.write(decodeHtml($("textarea#stepcodeTextarea7799").val()));
window.frames["iframe7799"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7799"]).load(function(){
$("#iframe7799").height($("#iframe7799").contents().find("body").height()+showittryitheight);
});
$("#iframe7799").height($("#iframe7799").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor7799.focus();
editor7799.setSize(null, "250");
$("#rendering7799").hide();
$("#rendered7799").hide();
});
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
};
var editor7799 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea7799"), {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
mode:"text/html",
theme:"eclipse",
selectionPointer: true,
lineWrapping: true,
extraKeys: {
"Alt-/": "autocomplete",
"Ctrl-F": "findPersistent",
"F8": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
editor7799.on("change",function(doc){
if(!binded7799){
$(window).bind('beforeunload',function(){
binded7799 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code7799 = newCode;
$("textarea#stepcodeTextarea7799").val(newCode);
if(alreadyWriteCode7799!=code7799){
lastModifedTime7799 = new Date().getTime();
$("#rendering7799").show();
$("#rendered7799").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor7799 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor7799.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv7799").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
通过如下方式可以进行纯数字遍历: <div v-for="i in 10">
");
window.frames["iframe_show7800"].document.write(decodeHtml($("textarea#stepcodeTextarea7800").val()));
window.frames["iframe_show7800"].document.close();
$(window.frames["iframe_show7800"]).load(function(){
$("#iframe_show7800").height($("#iframe_show7800").contents().find("body").height()+showittryitheight);
});
$("#iframe_show7800").height($("#iframe_show7800").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/vue.min.js"></script>
<div id="div1">
<div v-for="i in 10">
{{ i }}
</div>
</div>
<script>
new Vue({
el: '#div1'
})
</script>
<script src="http://127.0.0.1/study/vue.min.js"></script>
<div id="div1">
<div v-for="i in 10">
{{ i }}
</div>
</div>
<script>
new Vue({
el: '#div1'
})
</script>
");
window.frames["iframe7800"].document.write(decodeHtml(code7800));
window.frames["iframe7800"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7800"]).load(function(){
$("#iframe7800").height($("#iframe7800").contents().find("body").height()+showittryitheight);
});
$("#iframe7800").height($("#iframe7800").contents().find("body").height()+showittryitheight);
alreadyWriteCode7800 = code7800;
$("#rendering7800").hide();
$("#rendered7800").show();
}
var tRereshRetry2DemoPanel7800 = setInterval(rereshRetry2DemoPanel7800,1000);
var binded7800 = false;
$("textarea#stepcodeTextarea7800").keyup(function(){
if(!binded7800){
$(window).bind('beforeunload',function(){
binded7800 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code7800 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code7800!=newCode){
// window.frames["iframe7800"].document.write("
");
// window.frames["iframe7800"].document.write(decodeHtml($("textarea#stepcodeTextarea7800").val()));
// window.frames["iframe7800"].document.close();
// $(window.frames["iframe7800"]).load(function(){
// $("#iframe7800").height($("#iframe7800").contents().find("body").height()+showittryitheight);
// });
// code7800 = newCode;
// }
});
$(".tryButton7800").click(function(){
$("#tryDiv7800").show();
$("#stepcodeTextarea7800").focus();
$("#stepcodeTextarea7800").height(200);
$("#iframe7800").height(0);
window.frames["iframe7800"].document.write("
");
window.frames["iframe7800"].document.write(decodeHtml($("textarea#stepcodeTextarea7800").val()));
window.frames["iframe7800"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7800"]).load(function(){
$("#iframe7800").height($("#iframe7800").contents().find("body").height()+showittryitheight);
});
$("#iframe7800").height($("#iframe7800").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor7800.focus();
editor7800.setSize(null, "250");
$("#rendering7800").hide();
$("#rendered7800").hide();
});
var mixedMode = {
name: "htmlmixed",
scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
mode: null},
{matches: /(text|application)\/(x-)?vb(a|script)/i,
mode: "vbscript"}]
};
var editor7800 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea7800"), {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
mode:"text/html",
theme:"eclipse",
selectionPointer: true,
lineWrapping: true,
extraKeys: {
"Alt-/": "autocomplete",
"Ctrl-F": "findPersistent",
"F8": function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Esc": function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
});
editor7800.on("change",function(doc){
if(!binded7800){
$(window).bind('beforeunload',function(){
binded7800 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code7800 = newCode;
$("textarea#stepcodeTextarea7800").val(newCode);
if(alreadyWriteCode7800!=code7800){
lastModifedTime7800 = new Date().getTime();
$("#rendering7800").show();
$("#rendered7800").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor7800 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor7800.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv7800").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|