1.html页面
<div class="clearfix trade">
<div class="fc-price">应付金额: <span class="price">¥<em th:text="${totalMoney}" id="totalMoney"></em>.00</span></div>
<div class="fc-receiverInfo"> //这里是获取后台:model.addAttribute("totalMoney",order.getTotalMoney());
寄送至: <span id="receive-address">{{order.receiveAddress}}</span> //这个是获取下面vue中自己定义的order字段中的数据
收货人:<span id="receive-name">{{order.receiveContact}}</span>
<span id="receive-phone">{{order.receiveMobile}}</span> </div> </div>
2.必须有th:inline="javascript",[[${totalMoney}]]直接取值即可
<script th:inline="javascript">
var app = new Vue({
el:"#app",
data:{
order:{"receiveContact":[[${defAddr.contact}]],"receiveMobile":[[${defAddr.phone}]],"receiveAddress":[[${defAddr.address}]],"payType":1}
},
methods:{
chooseAddr:function (contact,mobile,address) {
app.$set(app.order,"receiveContact",contact);
app.$set(app.order,"receiveMobile",mobile);
app.$set(app.order,"receiveAddress",address);
},
add:function () {
axios.post("/api/worder/add",this.order).then(function (response) {
if (response.data.flag){
var totalMoney = [[${totalMoney}]];//js获取后台model中传来的值
alert("下单成功");
alert(totalMoney);
var orderId = response.data.data;
location.href="/api/worder/toPayPage?orderId="+orderId;
} else{
alert("下单失败");
}
})
}
}
})
</script>