Vue3基础
1.创建第一个vue页面
<script src="./js/vue.global.js"></script>
<div id="app">
{{msg}}
</div>
<script>
const app = Vue.createApp({
data(){
return{
msg:"hello vue"
}
}
}).mount("#app")
</script>
2.Vue基础
<script src="./js/vue.global.js"></script>
<div id="app">
<button @click="show_console()">在控制台显示</button>
{{msg}}{{name}}{{age}}
<br>
{{html_info}}
<span v-html="html_info"></span>
<br>
<a v-bind:href="a_herf">跳转到百度</a>
<a :href="a_herf">跳转到百度2</a>
<br>
表达式:支持js格式的表达式
{{1+2}}{{name.split("")}}
<br>
表达式:不支持if else这样的判断,只支持3元表达式
<br>
{{ok ? "真" :"假"}}
<br>
v-if 和 v-else
<br>
<span v-if="ok">v-if</span>
<span v-else-if="ok"> v-else-if</span>
<span v-else>v-else</span>
<br>
<span v-if="score=='A'">90-100</span>
<span v-else-if="score=='B'">80-90</span>
<span v-else-if="score=='C'">60-80</span>
<span v-else>不及格</span>
{{list}}
<ul>
<li v-for="s in list">{{s}}</li>
</ul>
<ul>
<li v-for="s,n in course">{{s}}{{n}}</li>
</ul>
<input type="text" v-model="input_value">
<br>
{{input_value}}
</div>
<script>
const app = Vue.createApp({
data(){
return{
msg:"hello vue"
,name:"张三"
,age:20
,html_info:"<h1>h1</h1>"
,a_herf:"http://www.baidu.com"
,ok:true
,score:"avrhghj"
,list:[1,2,3,4,5,6]
,course:["语文","数学","英语"]
,input_value:"x"
}
}
,methods:{
show_console(){
console.log(123);
}
}
}).mount("#app")
</script>
3.axios案例
<script src="./js/vue.global.js"></script>
<script src="./js/axios.min.js"></script><div id="app">{{msg}}</div>
<script>
const app = Vue.createApp({
data() {
return {
msg: "msg"
}
}
, mounted() {
axios.get("./json/data1.json")
.then(response => {
console.log(response.data);
})
.catch({
})
}
}).mount("#app")
axios.get("./json/data1.json")
.then(response => {
console.log(response.data);
})
.catch({
})
</script>