我直接上代码吧,是能获取到后台的值的,但是每次都先执行
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>
在main.js中的use,添加组件等等都放在new Vue的上面,mounted中可以不用this.$nextTick,延迟体验有些差;
<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写法不一样啊,想死