#vue应用的简单例子、$.get()方法及页面获取url里面的参数
###页面:
#####要先引入vue的js

<body>
<div v-if="hospital_name == '我'" id="data">123{{hospital_name}}</div>
</body>
</html>
<script>
    var doctorSharePage;//一定要设置全局变量
    $(function(){
        doctorSharePage = new Vue({
            el: '#data',
            data: {
                hospital_name:''
            },
            created: function () {//创建Vue时就执行
                var statusurl ="../test-vue/vue?";
                var location = window.location.href;//获取浏览器输入地址
                var index=location.indexOf("uOpenId")//获取浏览器输入参数下标
                if (index != -1) {
                    statusurl+=location.substring(index);//获取浏览器输入参数(uOpenId=...)

                }


                /*$.get(statusurl, function (data) {
                    doctorSharePage.hospital_name=data.name;

                });*/




                $.ajax({
                    type: "GET",
                    url: statusurl,
                    dataType: "json",
                    success: function (data) {
                        doctorSharePage.hospital_name=data.name;
                    },
                    error:function () {
                        alert("错误")
                    }
                });

            },

        })
    })
</script>

###controller:

@Controller
@RequestMapping("test-vue")
public class testVue {
    private UserService userService;
    public testVue(UserService userService){
        this.userService=userService;
    }
    @GetMapping(value = "vue")
    @ResponseBody
    public Map closeBabySchoolPopup(@RequestParam String uOpenId) {
        Map map =new HashMap();
        map.put("name","我");
        return map;//return "{\"name\" : \"我\"}";这种前台读出来会是?,出现乱码。数字和字符等无影响
    }
}
Logo

前往低代码交流专区

更多推荐