我直接上代码吧,是能获取到后台的值的,但是每次都先执行data() {
return {
message: message
}
},
我从后台获取的值根本就放不进去啊,网上的例子都是传的固定的值template>
<div id="indexTop">
<div>{{message}}</div>
</div>
</template>
<script>
import Vue from 'vue'
import axios from 'axios' var message = {}
export default {
name: "indexTop",
created: function () { this.$nextTick(function () {
axios.get('http://localhost:66/studio/banner')
.then(function (res) {
console.log(res.data);
message = res.data.length
})
.catch(function (err) {
console.log(err);
})
});
},
data() { return {
message: message
}
},
}</script>
2 回答
慕田峪9158850
TA贡献1794条经验 获得超7个赞
<template> <div id="indexTop"> <div>{{message}}</div> </div> </template> <script> import Vue from 'vue' import axios from 'axios' var message = {} export default { name: "indexTop", data() { return { message: message } }, mounted() { this.$nextTick(function () { var self = this; axios.get('http://localhost:66/studio/banner') .then(function (res) { console.log(res.data); self.message = res.data.length }) .catch(function (err) { console.log(err); }) }); } }</script>
我自己解决了,new vue和export default写法不一样啊,想死
添加回答
举报
0/150
提交
取消