码迷,mamicode.com
首页 > Web开发 > 详细

vue.js-读取/发送数据

时间:2017-06-13 11:31:05      阅读:213      评论:0      收藏:0      [点我收藏+]

标签: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-读取/发送数据

标签:self   读取   demo   idt   methods   span   click   height   utf-8   

原文地址:http://www.cnblogs.com/yueyue-love/p/6999798.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!