本来要开始讲解 Vue.js 里如何使用 Ajax了。 一般说来 Vue 不会直接使用原生的 Ajax 而是使用 ajax 框架。 而 fetch.js 就是眼下比较流行的一种 ajax 框架
{"name":"gareen","hp":"355"}
{"name":"gareen","hp":"355"}
如果要本地测试,可以在右上角下载 fetch.min.js
");
window.frames["iframe_show7834"].document.write(decodeHtml($("textarea#stepcodeTextarea7834").val()));
window.frames["iframe_show7834"].document.close();
$(window.frames["iframe_show7834"]).load(function(){
$("#iframe_show7834").height($("#iframe_show7834").contents().find("body").height()+showittryitheight);
});
$("#iframe_show7834").height($("#iframe_show7834").contents().find("body").height()+showittryitheight);
setTimeout(function(){
},500);
});
<script src="http://127.0.0.1/study/fetch.min.js"></script>
<div id="hero">
</div>
<script>
var url = "http://how2j.cn/study/json.txt"
fetch(url).then(function(response) {
response.json().then(function (jsonObject) {
var jsonString = JSON.stringify(jsonObject)
document.getElementById("hero").innerHTML = "通过fetch获取到的json数据:"+ jsonString;
})
}).catch(function(err){
console.log("Fetch错误:"+err);
})
</script>
<script src="http://127.0.0.1/study/fetch.min.js"></script>
<div id="hero">
</div>
<script>
var url = "http://how2j.cn/study/json.txt"
fetch(url).then(function(response) {
response.json().then(function (jsonObject) {
var jsonString = JSON.stringify(jsonObject)
document.getElementById("hero").innerHTML = "通过fetch获取到的json数据:"+ jsonString;
})
}).catch(function(err){
console.log("Fetch错误:"+err);
})
</script>
");
window.frames["iframe7834"].document.write(decodeHtml(code7834));
window.frames["iframe7834"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7834"]).load(function(){
$("#iframe7834").height($("#iframe7834").contents().find("body").height()+showittryitheight);
});
$("#iframe7834").height($("#iframe7834").contents().find("body").height()+showittryitheight);
alreadyWriteCode7834 = code7834;
$("#rendering7834").hide();
$("#rendered7834").show();
}
var tRereshRetry2DemoPanel7834 = setInterval(rereshRetry2DemoPanel7834,1000);
var binded7834 = false;
$("textarea#stepcodeTextarea7834").keyup(function(){
if(!binded7834){
$(window).bind('beforeunload',function(){
binded7834 = true;
return "xxxx";
});
}
var newCode = $(this).val()
code7834 = newCode;
/*below code is replaced by function rereshRetry2DemoPanel()*/
// if(code7834!=newCode){
// window.frames["iframe7834"].document.write("
");
// window.frames["iframe7834"].document.write(decodeHtml($("textarea#stepcodeTextarea7834").val()));
// window.frames["iframe7834"].document.close();
// $(window.frames["iframe7834"]).load(function(){
// $("#iframe7834").height($("#iframe7834").contents().find("body").height()+showittryitheight);
// });
// code7834 = newCode;
// }
});
$(".tryButton7834").click(function(){
$("#tryDiv7834").show();
$("#stepcodeTextarea7834").focus();
$("#stepcodeTextarea7834").height(200);
$("#iframe7834").height(0);
window.frames["iframe7834"].document.write("
");
window.frames["iframe7834"].document.write(decodeHtml($("textarea#stepcodeTextarea7834").val()));
window.frames["iframe7834"].document.close();
//load和下面的非load必需并存,因为如果代码用到了jquery就必须使用load的方式
$(window.frames["iframe7834"]).load(function(){
$("#iframe7834").height($("#iframe7834").contents().find("body").height()+showittryitheight);
});
$("#iframe7834").height($("#iframe7834").contents().find("body").height()+showittryitheight);
this.scrollIntoView(true);
editor7834.focus();
editor7834.setSize(null, "250");
$("#rendering7834").hide();
$("#rendered7834").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 editor7834 = CodeMirror.fromTextArea(document.getElementById("stepcodeTextarea7834"), {
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);
}
}
});
editor7834.on("change",function(doc){
if(!binded7834){
$(window).bind('beforeunload',function(){
binded7834 = true;
return "xxxx";
});
}
var newCode = doc.getValue();
code7834 = newCode;
$("textarea#stepcodeTextarea7834").val(newCode);
if(alreadyWriteCode7834!=code7834){
lastModifedTime7834 = new Date().getTime();
$("#rendering7834").show();
$("#rendered7834").hide();
}
// alert(doc.getValue());
});
$(".CodeMirror").addClass("form-control");
// var editor7834 = CodeMirror.fromTextArea(, {
// lineNumbers: true,
// styleActiveLine: true,
// matchBrackets: true,
// theme:"eclipse",
// });
editor7834.on("change",function(doc){
// alert(doc.getValue());
});
$("#tryDiv7834").hide();
});
$("div.codemirrorTips span").addClass("glyphicon glyphicon-asterisk");
1. 双击选中单词
2. 三击选中整行
3. CTRL+F 查找
4. F8 全屏编辑,再次点击恢复
|
渲染中
渲染完成
|