手写的vue.js要在div的id声明后后引入
因为要先有id为vue-app的div,vue才能获取相应的元素
//在前 <div id="app"> <h1>index.html</h1> <input type="button" value="测试springMVC处理Ajax" @click="testAjax"> </div>
//在后 <script type="text/javascript"> var vue=new Vue({ el:"#app", methods:{ testAjax(){ axios.post( "/pro16/test/ajax?id=1001", {username:"admin",password:"1234"} ).then(response=>{ console.log(response.data); }); } } }); </script>
或者加上window.οnlοad=function(){}可以使得该页面首先加载vue,vue.js的手写内容就可放在div之前
<script type="text/javascript"> window.οnlοad=function (){ var vue=new Vue({ el:"#app", methods:{ testAjax(){ axios.post( "/pro16/test/ajax?id=1001", {username:"admin",password:"1234"} ).then(response=>{ console.log(response.data); }); } } }); } </script> <div id="app"> <h1>index.html</h1> <input type="button" value="测试springMVC处理Ajax" @click="testAjax"> </div>