目录
- 实验目的
- 相关知识点
- 实验内容
- 图片的隐藏和显示
- 代码实现
- 效果
- 电影票房排序
- 代码实现
- 效果
- 代办事项记录
- 代码实现
- 效果
实验目的
(1)熟练掌握v-on 指令的用法,学会使用v-on 指令监听DOM元素的事件,并通过该事件触发调用事件处理程序。
(2)掌握v-on指令修饰符的基本用法。
相关知识点
(1)条件渲染: v-if 指令、v-else 指令、v-else-if 指令、v-show 指令
在前端程序设计中,经常需要控制某些DOM 元素的显示或隐藏,为此Vue. js提供了多个指令来实现条件渲染。
v-if指令可以根掘某个表达式的值(表示条件)决定是否输出DOM元素及其所包含的子元素,如果表达式的值为true (条件成立),则输出;否则,就移除。v-if 指令必须添加到某个元素上,如果需要对一组元素进行条件演染, 则需要使用 元素作为包装元素。
v-clsc指令的作用相当于js的if-clse中的clse了句,它与v-if指令配合使用。
v else if指令相当于js中的else if句,应州该指令可以实现多分支结构。
v- show指令勺v-il指令一样,可以根据表达式的估米次定是否显示或隐藏DOM元素。
但是,与v-if指令的区别在F:应用v-show指令的元素,尤论要判断的表达式的值足true还是false,该元索部始终会被渲染并保留在DOM中,表达式估的改变只是简单地切换元素的CSS 属性display,当表达式的值为falsc 时,该元素会添加个内联样式style-“displ ay:none”,从而隐藏该元素。
(2)循环消染: v-for 指令,遍历数组,数组更新检测,遍历对象
循环渲染又叫列表消染。通过循环渲染,可以将数组或对象中的数据进行循环遍历并渲染到DOM中。在Vue. js中,实现循环渲染的指令是v for指令。
Vue. js中提供了一-组 检测数组变化的变异方法,调用这些方法可以改变原始数组,并触发视图更新。除了变异方法外,Vue. js还提供了一些非变异方法,例如: filter、concat0、slice(等。 调用这些非变异方法不会改变原始数组,而是返回- -个新的数组。
此时,可以用新数组替换原来的数组。
在已经创建的实例中,可以使用全局方法Vue. set (object, key, value) 或实例方法
vm. $set (object, key, value) 向对象中添加响应式属性,同时触发视图更新。
v-for指令还可以用遍历整数,它根据接收的整数( 循环次数)将模板重复整数次。
实验内容
图片的隐藏和显示
(1)使用条件渲染指令(v-if、v-show) 指令实现图片的隐藏和显示控制。要求:点击按钮控制图片的显示和隐藏,同时按钮的文字发生响应改变。具体图片不限。
代码实现
<!DOCTYPE html>
<html>
<head>
<title>Vue 图片切换与页面跳转示例</title>
<meta charset="UTF-8">
</head>
<body>
<div id="app">
<!-- 图片切换部分 -->
<button @click="showImage = !showImage">
{{ showImage ? '隐藏图片' : '显示图片' }}
</button>
<br>
<img v-if="showImage" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAsJCQcJCQcJCQkJCwkJCQkJCQsJCwsMCwsLDA0QDBEODQ4MEhkSJRodJR0ZHxwpKRYlNzU2GioyPi0pMBk7IRP/2wBDAQcICAsJCxULCxUsHRkdLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCz/wAARCADqAXIDASIAAhEBAxEB/8QAHAABAAIDAQEBAAAAAAAAAAAAAAEFAgMEBgcI/8QARRAAAgICAQIEBAMEBgcGBwAAAQIAAwQRBRIhBhMxQRQiUWEycYEHFSORFjZCobPwJFJidIKx0SUmNHPB8UNkcnWiwuH/xAAWAQEBAQAAAAAAAAAAAAAAAAAAAQL/xAAVEQEBAAAAAAAAAAAAAAAAAAAAEf/aAAwDAQACEQMRAD8A+td47xEyyd47xEB3jvEQHeO8RAd47xEB3jvEQHeO8RAd47xEB3jvEQHeO8RAd47xEB3jvEQHeO8RAd47xEB3jvEQHeO8RAd47xEB3jvEQHeO8RAd47xEB3jvEQHeO8RAd47xEB3iIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIiAiIgIiICIlTxnJNm8h4pxWIK8ZyOPjVAADVb4dNh3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6uP7I12PfZ9g9cgYJWp7FUUHX1AAPea6sTDotyLqMbHqtyX8zIsqqRLLn/wBaxlGyfzM3iIHy7x3i+NKanvyOSOVwb2dD14lYxlo62+RcmtSSy+gDdZG/Yb3Pn1ZyFuobHNwyfNrGN8OXF/nMwVRUUIbq2dDU/Q3JYVfIcfyOC4BXLxb8cg6Pd0IB7/Q6nx7wFgfF+J8E2p1LxtGVmuD6C5NY6H9C2x+UD6Z4ZxfF2PjA+IORqyLGrTy8dakNmNr2tyV11N9fl/U+91TiYWO+RZj42PS+Qwe96aq62tZRoGwqASfzm4DXv9pMBERAREQEREBERAREQEREBERAREQESYgRERAREQEREBERAREQEREBERAREQEREBGoiAiIgNRqIgIiID/rPnfgbBFHiXx+3SAMXJTDT6gWZF9uv5BZ9EPoZ5fw5j+Vzf7QrNa83mcUb+v+hVW//v8A3wPUREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBOTGwq8bI5W9WZm5HKryrQQAEZMenGCrr7ID+s647QEREBERAREQEREBERAREQEREBERAREQJiREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQEREBErM/mcHjrfIvW42GgXjoVekqWKa6mYd/eYWc9x9V19Drf5lduNSPk+Sxr+ylG3rX3/yQtolaOXxjdn0Gq4NgVNdlHdLdChDYNKjlidfb3/lhXzmFZXk2GvIX4dK7XUoCxrtDsjDR136Tv6QLWJTt4g45amtKZWg9tYQVguSlPxBICk+3f8Av9DuWGNl05OMmVWHFbK7AMum+QkEa/QwOiJT1c/gXVWXKmQqInV86aZtMit0gb3rqG/5TKvnMG2vIepLnNFxqZFVRY3yNYrKGI7EDvvWu49oFt2iU9nP4FaY7tTlhb63sQmsDSrYKh1d+2yQBvX5TKzncCryupLm8yvzgawrIE2oJ6tjsN9+0C2jtKtebwGzEwh5/mvbZR1Gv5PMQ6K9Xp/099Tqy8ynDUNYrsPLus/hhTpal6jvqI/T/JAdUS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l+RflJK/KOxPrrtI8qj5iKq9sNN8i9xvej2myIVgErUaVEA2ToKANn1/nJKofVVPYjuAex9RMogYdFZ1tV7MG9B+Ie/5wqVrvpVV2dnpAGz99TOIERJiEREmIIiJMRCIiTEEREmIIiJMQIiTEEaz5mzpk17bETZEqv//Z" alt="图片">
//一张网络图片的url
<!-- 页面跳转部分 -->
<button @click="goToPage('/video')">跳转到电影排序</button>
<button @click="goToPage('/note')">跳转到代办事项页面</button>
</div>
<!-- 引入 Vue 和 Vue Router -->
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-router@3.0.7/dist/vue-router.js"></script>
<script>
// 定义路由组件
const VideoPage = { template: '<div>电影排序页面内容</div>' }
const OtherPage = { template: '<div>其他页面内容</div>' }
// 定义路由
const routes = [
{ path: '/video', component: VideoPage },
{ path: '/note', component: OtherPage }
]
// 创建 router 实例
const router = new VueRouter({
mode:'history',
routes // (缩写)相当于 routes: routes
})
// 创建和挂载根实例
new Vue({
router,
data: {
showImage: false // 控制图片的显示和隐藏
},
methods: {
goToPage(path) {
// 使用 $router.push 方法进行页面跳转
this.$router.push(path);
}
}
}).$mount('#app')
</script>
</body>
</html>
效果
电影票房排序
(2)使用循环渲染指令,实现电影票房排序功能。要求:点击相应按钮,实现电影票
房排序和按原始顺序进行反转。
代码实现
<!DOCTYPE html>
<html>
<head>
<title>Vue 电影票房排序示例</title>
<meta charset="UTF-8">
</head>
<body>
<div id="app">
<!-- 排序按钮 -->
<button @click="sortByBoxOffice">按票房排序</button>
<button @click="reverseOrder">反转顺序</button>
<!-- 电影列表 -->
<ul>
<li v-for="movie in movies" :key="movie.id">
{{ movie.name }} - 票房: {{ movie.boxOffice }}
</li>
</ul>
</div>
<!-- 引入 Vue -->
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script>
new Vue({
el: '#app',
data: {
movies: [
{ id: 1, name: '电影A', boxOffice: 900 },
{ id: 2, name: '电影B', boxOffice: 1200 },
{ id: 3, name: '电影C', boxOffice: 500 },
// 更多电影...
],
originalOrder: []
},
created() {
// 在组件创建时保存原始顺序
this.originalOrder = [...this.movies];
},
methods: {
sortByBoxOffice() {
// 按票房排序
this.movies.sort((a, b) => b.boxOffice - a.boxOffice);
},
reverseOrder() {
// 反转到原始顺序
this.movies = [...this.originalOrder];
}
}
});
</script>
</body>
</html>
效果
代办事项记录
(3)使用循环渲染指令,实现代办事项记录功能。要求:在输入框输入你的代办事
项,点击“添加”按钮,则进入未完成项列表中,同时数量增加,点击未完成项中的“删
除”按钮,该事项则进入已完成列表,同时数量增加。
代码实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Todo List</title>
</head>
<body>
<div id="app">
<h1>最近需完成的计划</h1>
<input v-model="newTodo" @keyup.enter="addTodo" placeholder="添加新的计划">
<ul>
<li v-for="(todo, index) in todos" :key="index">
<input type="checkbox" v-model="todo.completed">
<p :style="{ 'text-decoration': todo.completed ? 'line-through' : 'none' }">{{ todo.text }}</p>
<button @click="removeTodo(index)">删除</button>
<button @click="markCompleted(index)" v-if="!todo.completed">标记为已完成事项</button>
</li>
</ul>
<p id="total">最近需完成的计划: {{ totalTasks }}</p>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script>
new Vue({
el: '#app',
data: {
newTodo: '',
todos: []
},
computed: {
totalTasks() {
return this.todos.length;
}
},
methods: {
addTodo() {
if (this.newTodo.trim() !== '') {
this.todos.push({
text: this.newTodo,
completed: false
});
this.newTodo = '';
}
},
removeTodo(index) {
this.todos.splice(index, 1);
},
markCompleted(index) {
this.todos[index].completed = true;
}
}
});
</script>
</body>
</html>
效果
输入内容,点击回车
点击“标记为已完成事项”
点击删除