current position:Home>Web front-end development technology: Vuex state management
Web front-end development technology: Vuex state management
2023-01-25 11:22:07【nickdlk】
一、实验目的:
掌握VuexThe configuration method of the instance object.
掌握Vuex API接口的使用方法.
二、实验要求:
了解Vuex的基本概念.
掌握Vuex 下载安装方法.
编写程序完成以下实验内容并上交实验报告
三、实验内容:
(一)实验基础
1、Vuex插件
Component state is the data in the component、功能等信息,使用VuexCentrally manage the state of all components of the application,Make component state easy to maintain and share.
2、This experiment can be used for reference such as teaching materials through imitation【例6-9】的实现,初步掌握VuexRelevant knowledge and application methods.
(二)实验题
Please program to increase the list、删、改、查操作.
四、设计思路:
使用vuex存储数据,增加操作使用commit提交到mutation,push到列表;Deletions and modifications are subject to changeid传入到mutation,Traverse the data to find the corresponding onetext,Modifications are passed in at the same timetextassign to the original variable;查找使用filter函数.
五、实验过程中遇到的问题及解决手段:
Commit提交多个参数,It needs to be surrounded by curly braces to form a key-value pair transfer.
六、程序源代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="vue.js"></script>
<script src="vuex.js"></script>
</head>
<body>
<div id="app">
<h2>列表查询</h2>
<input type="text" v-model="id">
<button @click="search">搜索</button>
<p>搜索结果:{
{ this.$store.getters.search }}</p>
ID : <input type="text" v-model="add_id">
Name :<input type="text" v-model="add_text">
<button @click="m_add">增加</button>
</p>
删除ID为 : <input type="text" v-model="delete_id">
<button @click="m_delete">删除</button>
</p>
修改ID : <input type="text" v-model="modify_id">
为:<input type="text" v-model="modify_text">内容
<button @click="m_modify">修改</button>
<ul>
<li v-for="item in this.$store.state.todos">{
{ item }}</li>
</ul>
</div>
<script> const store = new Vuex.Store({
state: {
todos: [ {
id: 1, text: '内容1' }, {
id: 2, text: '内容2' }, {
id: 3, text: '内容3' }, {
id: 4, text: '内容4' }, {
id: 5, text: '内容5' }, {
id: 6, text: '内容6' }, ], id: 0 }, mutations: {
search (state, id) {
state.id = id }, addlist (state,param) {
console.log("addlist",add) state.todos.push({
id:param.id,text:param.text})//添加到数组 }, delete(state,id){
state.todos.map((v,i)=> {
if(v.id == id){
state.todos.splice(i,1) } }) }, modify(state,param){
state.todos.map((v,i)=> {
if(v.id == param.id){
state.todos[i].text = param.text } }) } }, actions: {
}, getters: {
search: state => {
return state.todos.filter(todo => todo.id == state.id) }, } }) var vm = new Vue({
el: '#app', data: {
id: '' ,add_id:'',add_text:'',delete_id:"",modify_id:"",modify_text:""}, store, methods: {
//查找 search () {
this.$store.commit('search', this.id) }, //增加 m_add () {
this.$store.commit('addlist',{
id:this.add_id,text:this.add_text})//键值对传参 }, //删除 m_delete(){
this.$store.commit('delete', this.delete_id) }, //修改 m_modify(){
this.$store.commit('modify', {
id:this.modify_id,text:this.modify_text}) } } }) </script>
</body>
</html>
copyright notice
author[nickdlk],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2023/025/202301251105496740.html
The sidebar is recommended
- Based on VirtualBox centos7 virtual machine installation
- JVM process cache - Caffeine
- Code Caprice No24 | Backtracking Algorithm Theoretical Basis, 77. Combination
- The Road to Algorithm Practice——[String] Leetcode 824 Goat Latin
- Git summary - Prompt to submit or temporarily store changes when switching to a branch
- Productivity tools - [gitlab configuration] One-time configuration of GitLab account
- Echo+Vue+ElementUI management background source code
- Revel+Vue+ElementUI framework use and build tutorial
- Basic practice tutorial of Revel+Vue+ElementUI framework
- Go Web Development Revel+Vue+ElementUI Framework Practical Tutorial
guess what you like
Construction and deployment tutorial of Revel+Vue+ElementUI framework
8. Java loop advanced comprehensive exercises - infinite loop and jump control statement, every seven passes, square root, judging whether it is a prime number, guessing number games
Control statement + exception handling perfect lucky draw applet-java basics
9. Java Array Knowledge Encyclopedia
Lucky draw applet-java basics
Java basic implementation calculator applet
The front end of actual combat: copy write millet's official website on the first day
1. Linux application programming and network programming---file IO notes in Linux system
7. Linux application programming and network programming --- thread full solution Notes
[Front-end notes - CSS] 10. Cascading and inheritance + selector
Random recommended
- 8. Linux application programming and network programming---Linux network programming notes
- [Java|golang] 1828. Count the number of points in a circle
- Add environment variables under Linux system and will not overwrite the previous method of adding environment variables
- 2 · Linux application programming and network programming - file attributes notes
- Redis interview questions (classic 7 questions)
- [Front-end notes——CSS] 11. Box model + background and border
- C + + large Numbers together, according to a combined
- 3. Linux application programming and network programming --- get system information notes
- The use and principle of Kafka message queue
- 5. Linux application programming and network programming---signal notes in Linux
- 6 · Linux application programming and system programming - senior IO notes
- Java collection common interview questions (4)
- 072-JAVA project training: Imitation QQ instant messaging software series lecture 7 (explaining the realization of the chat interface and functions)
- Coordination center performance comparison: how zookeeper solves the load balancing problem
- 070-JAVA project training: imitation QQ instant messaging software series lecture five (explain user registration function)
- Ubuntu installation and configuration (brief)
- 073-JAVA project training: imitation QQ instant messaging software series lecture eight (explain query and add friend function)
- SQL injection classification and error injection EXP
- All basic commands in linux fail, showing that the command cannot be found
- 4. Linux application programming and network programming---Linux process full solution notes (difference between process and program)
- Linux system - basic IO
- Hanlp's understanding of user-defined dictionaries (java version)
- Brief description and configuration of Maven
- 071-JAVA project training: imitation QQ instant messaging software series lecture six (explaining the function of QQ main interface)
- 【Maximum LeetCode】January Algorithm Training (12) Linked List
- 【Max LeetCode】January Algorithm Training (13) Doubly Linked List
- [Big Data Management] Java implements Bloom filter
- [Maximum LeetCode] Algorithm training in January (14) stack
- [Machine Learning] Adaboost Integrated Algorithm
- [Big Data Management] Java implements cuckoo filter (CF)
- Chaozhou Xiangqiao: "Charming Ancient City, Cultural Sharing" Spring Festival Intangible Cultural Heritage Market Opens
- [Big data management] Java realizes the dictionary tree TireTree
- [Max LeetCode] January Algorithm Training (11) Matrix
- New Express (Web framework based on HTTP module encapsulation NodeJS)
- JavaScript error-prone questions (stack processing, call function, prototype chain questions)
- Space "travel", lion and crane dance, intangible cultural heritage experience...During the Spring Festival, Zhuhai Jinwan is so fun!
- Wine 8.0 official release: better support for running Windows applications on Linux and other systems
- Zhongke Sugon: Sugon's new computer "participates in" "The Wandering Earth 2"
- Linux actual combat notes finishing (1.24)
- Automatically execute the specified sql when the springBoot project starts