vue.js-讀取/發送資料

來源:互聯網
上載者:User

標籤:self   讀取   demo   idt   methods   span   click   height   utf-8   

<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>vue-讀取/發送資料</title>
<style type="text/css">
* {
margin: 0;
padding: 0
}

table,
td {
border: 1px solid #cccccc;
border-collapse: collapse;
}

table {
width: 1090px;
margin: 20px auto;
}

tr {
line-height: 30px;
}

td {
text-align: center;
}

.demo_input {
width: 500px;
height: 500px;
border: 1px solid red;
margin: 0 auto;
text-align: center;
}

.demo_input input {
width: 200px;
height: 30px;
margin: 5px auto;
}
</style>
<script src="js/vue.js"></script>
<script src="js/jquery.js"></script>

</head>

<body>

<div id="demo">
<table border="1">
<tr>
<th>ID</th>
<th>書名</th>
<th>作者</th>
<th>價格</th>
</tr>
<tr v-for="books in book">
<td>{{books.id}}</td>
<td>{{books.name}}</td>
<td>{{books.author}}</td>
<td>{{books.price}}</td>
</tr>
<tr>
<td colspan="4"><button v-on:click="showData">點我</button></td>
</tr>
</table>

<hr />
<div class="demo_input">
<p>帳號:<input type="text" placeholder="請輸入帳號" id="name" /></p>

<p>密碼:<input type="text" placeholder="請輸入密碼" id="pwd" /></p>
<p>
<!--<button onclick="login()">登入</button>-->
<button v-on:click="login()">登入</button>
</p>
</div>
</div>
<script>
/*vue結合ajax資料讀取*/
var demo = new Vue({
el: ‘#demo‘,
data: {
book: ‘‘,
},
mounted: function() {
var _self = this;
$.ajax({
type: "get",
url: "vue.json",
dataType: "json",
success: function(data) {
_self.book = data.books;
console.log(_self.book)
}
});
},
methods: {
showData: function() {
var _self = this;
$.ajax({
type: "get",
url: "vue.json",
dataType: "json",
success: function(data) {
_self.book = data.books;
console.log(_self.book)
}
});
},
login: function() {
$.ajax({
type: "get",
url: "aaa.php",
data: {
"name": $("#name").val(),
"pwd": $("#pwd").val(),
},
dataType: "text",
success: function() {
console.log("成功了")
}
});
}
}

})
</script>
</body>

</html>

vue.js-讀取/發送資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.