vue的简单使用
vue狂神笔记
1.v-model的使用
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<h1>{{message}}</h1>
输入的文本<input type="text" v-model="peopleSex">{{peopleSex}}
<br>
<input type="radio" name="sex" value="男" v-model="peopleSex">男
<input type="radio" name="sex" value="女" v-model="peopleSex">女
<p> 选中了{{peopleSex}}</p>
</div>
<script type="text/javascript" src="https://unpkg.com/vue"></script>
<script>
var vm=new Vue({
el:"#app",
data:{
peopleSex:"",
message:"华哥哥"
},
methods:{
sayHi:function () {
alert(this.message)
}
}
});
</script>
</body>
</html>
2.component的例子
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<biaoqian v-for="item in items" v-bind:message="item">
</biaoqian>
</div>
<script type="text/javascript" src="https://unpkg.com/vue"></script>
<script>
Vue.component("biaoqian",{
props:['message'],
template:'<h1>{{message}}</h1>'
});
var vm=new Vue({
el:"#app",
data:{
items:["java","php","c++"]
}
});
</script>
</body>
</html>
3.mounted的使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="vue">
<div>{{info.name}}</div>
</div>
<script type="text/javascript" src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.bootcss.com/qs/6.5.2/qs.min.js"></script>
<script type="text/javascript">
var vm=new Vue({
el:"#vue",
data(){
return{
info:{
name:null,
adddress:{
street:null,
city:null,
country:null
}
}
}
},
mounted(){
axios.get('data.json').then(response=>(this.info=response.data))
}
});
</script>
</body>
</html>