|
步骤
1
:
v-if
步骤
2
:
v-else
步骤
3
:
v-else-if
通过toggle函数切换show的值。 通过v-if 语句,当show 是true的时候,显示当前元素 <div v-if="show"> 默认这一条是看得见的</div>
");
window.frames["iframe_show7795"].document.write(decodeHtml($("textarea#stepcodeTextarea7795").val()));
window.frames["iframe_show7795"].document.close();
$(window.frames["iframe_show7795"]).load(function(){
$("#iframe_show7795").height($("#iframe_show7795").contents().find("body").height()+showittryitheight);
});
$("#iframe_show7795").height($("#iframe_show7795").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/vue.min.js"></script>
<div id="div1">
<button v-on:click="toggle">切换隐藏显示</button>
<div v-if="show"> 默认这一条是看得见的</div>
</div>
<script>
new Vue({
el: '#div1',
data: {
show:true
},
methods:{
toggle: function(){
this.show=!this.show;
}
}
})
</script>
<script src="http://127.0.0.1/study/vue.min.js"></script>
<div id="div1">
<button v-on:click="toggle">切换隐藏显示</button>
<div v-if="show"> 默认这一条是看得见的</div>
</div>
<script>
new Vue({
el: '#div1',
data: {
show:true
},
methods:{
toggle: function(){
this.show=!this.show;
}
}
})
</script>
");
window.frames["iframe7795"].document.write(decodeHtml(code7795));
window.frames["iframe7795"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7795"]).load(function(){
$("#iframe7795").height($("#iframe7795").contents().find("body").height()+showittryitheight);
});
$("#iframe7795").height($("#iframe7795").contents().find("body").height()+showittryitheight);
alreadyWriteCode7795 = code7795;
$("#rendering7795").hide();
$("#rendered7795").show();
}
var tRereshRetry2DemoPanel7795 = setInterval(rereshRetry2DemoPanel7795,1000);
var binded7795 = false;
$("textarea#stepcodeTextarea7795").keyup(function(){
if(!binded7795){
$(window).bind('beforeunload',function(){
binded7795 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code7795 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code7795!=newCode){
// window.frames["iframe7795"].document.write("
");
// window.frames["iframe7795"].document.write(decodeHtml($("textarea#stepcodeTextarea7795").val()));
// window.frames["iframe7795"].document.close();
// $(window.frames["iframe7795"]).load(function(){
// $("#iframe7795").height($("#iframe7795").contents().find("body").height()+showittryitheight);
// });
// code7795 = newCode;
// }
});
$(".tryButton7795").click(function(){
$("#tryDiv7795").show();
$("#stepcodeTextarea7795").focus();
$("#stepcodeTextarea7795").height(200);
$("#iframe7795").height(0);
window.frames["iframe7795"].document.write("
");
window.frames["iframe7795"].document.write(decodeHtml($("textarea#stepcodeTextarea7795").val()));
window.frames["iframe7795"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7795"]).load(function(){
$("#iframe7795").height($("#iframe7795").contents().find("body").height()+showittryitheight);
});
$("#iframe7795").height($("#iframe7795").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor7795.focus();
editor7795.setSize(null, "250");
$("#rendering7795").hide();
$("#rendered7795").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 editor7795 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea7795"), {
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);
}
}
});
editor7795.on("change",function(doc){
if(!binded7795){
$(window).bind('beforeunload',function(){
binded7795 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code7795 = newCode;
$("textarea#stepcodeTextarea7795").val(newCode);
if(alreadyWriteCode7795!=code7795){
lastModifedTime7795 = new Date().getTime();
$("#rendering7795").show();
$("#rendered7795").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor7795 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor7795.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv7795").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
v-else 用法,如代码所示,没什么好说的。。。
");
window.frames["iframe_show7796"].document.write(decodeHtml($("textarea#stepcodeTextarea7796").val()));
window.frames["iframe_show7796"].document.close();
$(window.frames["iframe_show7796"]).load(function(){
$("#iframe_show7796").height($("#iframe_show7796").contents().find("body").height()+showittryitheight);
});
$("#iframe_show7796").height($("#iframe_show7796").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/vue.min.js"></script>
<div id="div1">
<button v-on:click="moyiba"> 摸一把彩票 10%的几率,建议一边点击一边心里默数,多少次了,站长表示最多点了40次才中奖,妈蛋~ </button>
<div v-if="show"> 中了500万!</div>
<div v-else>谢谢惠顾!</div>
</div>
<script>
new Vue({
el: '#div1',
data: {
show:false
},
methods:{
moyiba: function(){
this.show=Math.random()<0.1
}
}
})
</script>
<script src="http://127.0.0.1/study/vue.min.js"></script>
<div id="div1">
<button v-on:click="moyiba"> 摸一把彩票 10%的几率,建议一边点击一边心里默数,多少次了,站长表示最多点了40次才中奖,妈蛋~ </button>
<div v-if="show"> 中了500万!</div>
<div v-else>谢谢惠顾!</div>
</div>
<script>
new Vue({
el: '#div1',
data: {
show:false
},
methods:{
moyiba: function(){
this.show=Math.random()<0.1
}
}
})
</script>
");
window.frames["iframe7796"].document.write(decodeHtml(code7796));
window.frames["iframe7796"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7796"]).load(function(){
$("#iframe7796").height($("#iframe7796").contents().find("body").height()+showittryitheight);
});
$("#iframe7796").height($("#iframe7796").contents().find("body").height()+showittryitheight);
alreadyWriteCode7796 = code7796;
$("#rendering7796").hide();
$("#rendered7796").show();
}
var tRereshRetry2DemoPanel7796 = setInterval(rereshRetry2DemoPanel7796,1000);
var binded7796 = false;
$("textarea#stepcodeTextarea7796").keyup(function(){
if(!binded7796){
$(window).bind('beforeunload',function(){
binded7796 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code7796 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code7796!=newCode){
// window.frames["iframe7796"].document.write("
");
// window.frames["iframe7796"].document.write(decodeHtml($("textarea#stepcodeTextarea7796").val()));
// window.frames["iframe7796"].document.close();
// $(window.frames["iframe7796"]).load(function(){
// $("#iframe7796").height($("#iframe7796").contents().find("body").height()+showittryitheight);
// });
// code7796 = newCode;
// }
});
$(".tryButton7796").click(function(){
$("#tryDiv7796").show();
$("#stepcodeTextarea7796").focus();
$("#stepcodeTextarea7796").height(200);
$("#iframe7796").height(0);
window.frames["iframe7796"].document.write("
");
window.frames["iframe7796"].document.write(decodeHtml($("textarea#stepcodeTextarea7796").val()));
window.frames["iframe7796"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7796"]).load(function(){
$("#iframe7796").height($("#iframe7796").contents().find("body").height()+showittryitheight);
});
$("#iframe7796").height($("#iframe7796").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor7796.focus();
editor7796.setSize(null, "250");
$("#rendering7796").hide();
$("#rendered7796").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 editor7796 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea7796"), {
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);
}
}
});
editor7796.on("change",function(doc){
if(!binded7796){
$(window).bind('beforeunload',function(){
binded7796 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code7796 = newCode;
$("textarea#stepcodeTextarea7796").val(newCode);
if(alreadyWriteCode7796!=code7796){
lastModifedTime7796 = new Date().getTime();
$("#rendering7796").show();
$("#rendered7796").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor7796 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor7796.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv7796").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
");
window.frames["iframe_show7797"].document.write(decodeHtml($("textarea#stepcodeTextarea7797").val()));
window.frames["iframe_show7797"].document.close();
$(window.frames["iframe_show7797"]).load(function(){
$("#iframe_show7797").height($("#iframe_show7797").contents().find("body").height()+showittryitheight);
});
$("#iframe_show7797").height($("#iframe_show7797").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/vue.min.js"></script>
<div id="div1">
<button v-on:click="toutai"> 看看下辈子投胎是做什么的 </button>
<div v-if="number>98"> 神仙</div>
<div v-else-if="number>95"> 国家领导人</div>
<div v-else-if="number>90"> 大富商</div>
<div v-else-if="number>80"> 大企业主</div>
<div v-else-if="number>70"> 演艺明星</div>
<div v-else-if="number>60"> 小企业主</div>
<div v-else-if="number>50"> 普通公务员</div>
<div v-else-if="number>40"> 小个体户</div>
<div v-else-if="number>30"> 血汗工厂工人</div>
<div v-else-if="number>20"> 偏远山区农民</div>
<div v-else> 流浪汉</div>
</div>
<script>
new Vue({
el: '#div1',
data: {
number:0
},
methods:{
toutai: function(){
this.number=Math.random()*100
}
}
})
</script>
<script src="http://127.0.0.1/study/vue.min.js"></script>
<div id="div1">
<button v-on:click="toutai"> 看看下辈子投胎是做什么的 </button>
<div v-if="number>98"> 神仙</div>
<div v-else-if="number>95"> 国家领导人</div>
<div v-else-if="number>90"> 大富商</div>
<div v-else-if="number>80"> 大企业主</div>
<div v-else-if="number>70"> 演艺明星</div>
<div v-else-if="number>60"> 小企业主</div>
<div v-else-if="number>50"> 普通公务员</div>
<div v-else-if="number>40"> 小个体户</div>
<div v-else-if="number>30"> 血汗工厂工人</div>
<div v-else-if="number>20"> 偏远山区农民</div>
<div v-else> 流浪汉</div>
</div>
<script>
new Vue({
el: '#div1',
data: {
number:0
},
methods:{
toutai: function(){
this.number=Math.random()*100
}
}
})
</script>
");
window.frames["iframe7797"].document.write(decodeHtml(code7797));
window.frames["iframe7797"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7797"]).load(function(){
$("#iframe7797").height($("#iframe7797").contents().find("body").height()+showittryitheight);
});
$("#iframe7797").height($("#iframe7797").contents().find("body").height()+showittryitheight);
alreadyWriteCode7797 = code7797;
$("#rendering7797").hide();
$("#rendered7797").show();
}
var tRereshRetry2DemoPanel7797 = setInterval(rereshRetry2DemoPanel7797,1000);
var binded7797 = false;
$("textarea#stepcodeTextarea7797").keyup(function(){
if(!binded7797){
$(window).bind('beforeunload',function(){
binded7797 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code7797 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code7797!=newCode){
// window.frames["iframe7797"].document.write("
");
// window.frames["iframe7797"].document.write(decodeHtml($("textarea#stepcodeTextarea7797").val()));
// window.frames["iframe7797"].document.close();
// $(window.frames["iframe7797"]).load(function(){
// $("#iframe7797").height($("#iframe7797").contents().find("body").height()+showittryitheight);
// });
// code7797 = newCode;
// }
});
$(".tryButton7797").click(function(){
$("#tryDiv7797").show();
$("#stepcodeTextarea7797").focus();
$("#stepcodeTextarea7797").height(200);
$("#iframe7797").height(0);
window.frames["iframe7797"].document.write("
");
window.frames["iframe7797"].document.write(decodeHtml($("textarea#stepcodeTextarea7797").val()));
window.frames["iframe7797"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7797"]).load(function(){
$("#iframe7797").height($("#iframe7797").contents().find("body").height()+showittryitheight);
});
$("#iframe7797").height($("#iframe7797").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor7797.focus();
editor7797.setSize(null, "250");
$("#rendering7797").hide();
$("#rendered7797").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 editor7797 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea7797"), {
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);
}
}
});
editor7797.on("change",function(doc){
if(!binded7797){
$(window).bind('beforeunload',function(){
binded7797 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code7797 = newCode;
$("textarea#stepcodeTextarea7797").val(newCode);
if(alreadyWriteCode7797!=code7797){
lastModifedTime7797 = new Date().getTime();
$("#rendering7797").show();
$("#rendered7797").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor7797 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor7797.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv7797").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|
代码高亮插件双击即可选中,不过部分同学反应,通过代码高亮插件复制的代码无法在IDEA里正常显示,这里提供TEXTAREA的方式,方便复制,谢谢
1. 自行完成练习
根据练习目标尽量自己实现代码效果,期间会碰到疑问,难题,和自己不懂的地方,这些都是必要的过程
2. 带着疑问查看答案
完成过程中,碰到无法解决的问题,带着疑问,查看答案,分析答案的解决思路
3. 查看答案讲解视频
依然有不明白的地方,点开视频讲解,带着疑问,听视频讲解有问题的部分
4. 再做一遍
理解后,再从头做一遍,把有疑问的地方都捋清楚
5. 总结
最后再总结一遍,总结思路,总结解决办法,以后遇到类似的问题,怎么处理
HOW2J公众号,关注后实时获知布最新的教程和优惠活动,谢谢。
提问之前请登陆
|