如何使用vue.js 实现前台html页面和后台的数据绑定
前台html页面:<!DOCTYPE html><html><head><meta charset="UTF-8"><title>首页</title><script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></s...
·
前台html页面:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>首页</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
</head>
<body>
<div class="containter">
<p>{{name}}</p>
</div>
</body>
<script type="text/javascript">
$(document).ready(function() {
$.getJSON('IndexController.do',{"name":"wdg"},function(result){
new Vue({
el:'.containter',
data:{
name:result.name
}
});
});
});
</script>
</html>
对应的后台:
package com.wdg.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONObject;
@Controller
public class LoginController
{
@RequestMapping("/IndexController")
public @ResponseBody String pageload(String name){
System.out.println(name);
JSONObject jsonRtn=new JSONObject();
jsonRtn.put("name", "wdg");
return jsonRtn.toString();
}
}
难点在于:我们是先调用$.getJSON(),在回调的函数里面实现页面的渲染
希望对你有所帮助,
更多推荐
已为社区贡献3条内容
所有评论(0)