• 我爱java系列---【thymeleaf中js如何取后台model中传来的值?】


    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>
    愿你走出半生,归来仍是少年!
  • 相关阅读:
    2021.4.4(每周总结)
    2021.4.2
    2021.4.1
    2021.3.31
    2021.3.30
    2021.3.29
    2021.3.28(每周总结)
    2021.3.26
    C语言中指针与取地址符&详解
    使用JDBC连接、操作数据库、实现数据处理
  • 原文地址:https://www.cnblogs.com/hujunwei/p/11478343.html
Copyright © 2020-2023  润新知