export default { data() { return { name: "jack", name1:"rose", name2:"lili" } }, }
<div class="about" id="about"> <h1>This is an about page</h1> <MyAddress></MyAddress> <p>{{name}}</p> <p>{{name1}}</p> <p>{{name2}}</p> <p>{{getData()}}</p> </div>
methods:{ getData(){ this.name = "jackssss"; console.log("要输出名字了",this.name) } },
<div class="about" id="about"> <h1>This is an about page</h1> <p>{{getData()}}</p> </div>
import Address from "@/views/Address"
components:{ MyAddress:Address }
<div class="about" id="about"> <h1>This is an about page</h1> <MyAddress></MyAddress> </div>
<template> <div class="about" id="about"> <div v-html="innerMsg" v-show="show" v-if="exist"></div> </div> </template> <script> export default { data() { return { innerMsg:"<p>这是一个内置的标签</p>", show: false, exist: true, } }, } </script>
<template> <div id="app"> <p v-for="key in order" :key="key"> {{key}} </p> </div> </template> <script> export default { data() { return { order:["111","222","333","444","555"] } } } </script>
<template> <div id="app"> <p v-for="(key,value) in student" :key="key"> {{key.id}}---{{key.name}}--{{key.age}}---{{value}} </p> </div> </template> <script> export default { data() { return { order:["111","222","333","444","555"], student:[ {id:1,name:"jack",age:12}, {id:2,name:"rise",age:12}, {id:3,name:"robin",age:12}, ] } } } </script>
<template> <div id="app"> <input type="radio" v-model="hobby" value="游泳">swim <input type="radio" v-model="hobby" value="打兵乓球">ping-pong <input type="radio" v-model="hobby" value="打羽毛球">table-tennis </div> <button @click="showHobby()">点击</button> </template> <script> export default{ data() { return { hobby:[] } }, methods:{ showHobby(){ console.log(this.hobby) } } } </script>
<input type="checkbox" v-model="hobby" value="游泳">swim
<template> <div id="app"> <p v-for="item in goods" :key="item.name"> {{item.name}}---{{item.number}} <button @click="changeNumberAdd(item)">+</button> <button @click="changeNumberReduce(item)">-</button> </p> </div> </template> <script> export default{ data() { return { goods:[{ name:"anple", number:9, }, { name:"banana", number:9, }, { name:"strawberry", number:9, }, ], cal:'' } }, methods:{ changeNumberAdd(item){ console.log("商品的数量",item.number) item.number ++; }, changeNumberReduce(item){ console.log("商品的数量",item.number) if(item.number >= 1) item.number --; } } } </script>
changeNumber(item,event){ var inner = event.currentTarget.innerHTML; if(inner == '+'){ item.number ++; } if(inner =='-' && item.number >= 1){ item.number --; } }
<button @click="changeNumberAdd(item)" ref="button" value="and">+</button>
<button @click="changeNumberAdd(item)" ref="button" value="and" id="button">+</button> <button @click="changeNumberReduce(item)" ref="button" value="red" id="button">-</button>
<button @click="changeNumberAdd(item,$event)" ref="button" value="" id="button">+</button>
changeNumberAdd(item ,event){ item.number ++; var el = event.currentTarget.innerHTML var ele = event.target.innerHTML console.log(el,ele) console.log("商品的数量",item.number) },
参考:vue.js click点击事件获取当前元素对象
<template> <div id="app"> <ul @click="click1()"> <li @click="click2()">ppp</li> </ul> </div> </template> <script> export default{ data() { return { } }, methods:{ click1(){ console.log("这是一个冒泡") }, click2(){ console.log("这也是一个冒泡") } } } </script>
<ul @click="click1()">ll <li @click.stop="click2()">ppp</li> </ul>
methods:{ getResource(){ fetch("data.json").then(res=>{ return res.json() }).then(res=>{ console.log("得到数据") console.log(res[0].name,res[0].age, res[0].address) }) } }
methods:{ getResource(){ fetch("data.json").then(res=>{ return res.json() }).then(res=>{ console.log("得到数据") console.log(res) console.log('axios',axios) }) }, getResByAxios(){ axios.get('data.json').then(response=>{ console.log("response",response.data) }).catch(error=>{ console.log(error) }) }, getResAxiosConfig(){ axios({ methods:'get', data:{ name:'jack', }, url:'data.json', timeout: 1000, }).then(res=>{ console.log("得到自己的一些数据",res.data) }) } }