<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="lib/vue.js"></script>
<script type="text/javascript" src="lib/jquery.js"></script>
</head>
<body>
<div id="app">
<a v-for="list in msgList">{{list.message}}</a>
</div>
</body>
<script type="text/javascript">
var arr=new Array();
var message=$.ajax({
url: '/laravel/public/DanmakuR/DanmakuR_main_player_video_message_center/1',
type: 'get',
dataType: 'json',
})
.done(function() {
for (var i = 0; i < message.responseJSON.length; i++) {
arr[i]={message:message.responseJSON[i].message,url:message.responseJSON[i].url};
}
})
.fail(function() {
//console.log("error");
})
.always(function() {
//console.log("complete");
});
console.log(arr);
var app=new Vue({
el:"#app",
data:{
msgList:arr,
},
});
</script>
</html>
ajax返回的数据
[{"uuid":"22056b8f-aa6c-11e7-94fa-005056c00001","message":"\u6d4b\u8bd5\u8fde\u63a5","url":"http:\/\/192.168.1.1"},{"uuid":"75f1db62-aa6c-11e7-94fa-005056c00001","message":"test2","url":"http:\/\/192.168.1.2"}]
涉及到生命周期,在created发送ajax请求