前端VueVue 筑基突破nodaoli2024-05-152024-11-30记事本123456789101112131415161718192021222324252627282930313233343536373839404142434445464748<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>notepad</title> <script src="vue.global.min.js"></script></head><body> <div id="app"> <!-- 定义一个文本框 --> <input type="text" v-model="data.content"> <!-- 添加按钮 --> <!-- 调用data对象的list属性,使用数组的push方法,content是双向绑定 --> <button @click="data.list.push(data.content)">添加</button> <!-- 直接把数组定义为空数组,就可以达到清空的效果 --> <button @click="data.list = []">清空</button> <ul> <!-- 循环输出数组内容,并返回下表 --> <li v-for="(value,index) in data.list"> <!-- splice方法接受两个参数,第一个是下表,第二个是删除个数 --> {{value}} <button @click="data.list.splice(index,1)">删除</button> </li> </ul> <hr> <!-- 打印数组长度 --> {{ data.list.length }} </div> <script> const { createApp,reactive } = Vue const app = createApp({ setup() { // 定义一个data对象 const data = reactive({ content:"icewolf-li.top", list: ['不讲道李','苹果'] }) return { data } } }).mount('#app') </script></body></html> 图片轮播12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>图片轮播</title> <script src="vue.global.min.js"></script></head><body> <div id="app"> <input type="text" v-model="num"> <br> <img :src="`img/${num}.jpg`" style="width: 200px;"> <hr> <button @click="prev">上一张</button> <button @click="next">下一张</button> <ul> <li v-for="value in 4"> <a href="#" @click="jump(value)">{{value}}</a> </li> </ul> </div> <script> const { createApp,ref,reactive } = Vue; createApp({ setup() { const num = ref(1) function next() { num.value++ if(num.value > 4) { num.value = 1 } } const prev = () => { num.value-- if(num.value < 1) { num.value = 4 } } const jump = (value) => { num.value = value } return { num, next, prev, jump } } }).mount('#app') </script></body></html>