vuex最详细笔记总结,这些东西你真的了解吗?

news2024/9/28 17:22:20

1.vuex是啥?

简单来说就是管理数据的,相当于一个仓库,里面存放着各种需要共享的数据,所有组件都可以拿到里面的数据

2.什么时候使用vuex

1.多个组件依赖于同一状态
2.来自不同组件的行为需要变更同一状态
总之,就是vuex作为一个仓库,任何组件都可以去在这个仓库拿数据,也可以修改这个仓库中的数据。

3.vuex实现原理

在这里插入图片描述
在这里插入图片描述

注意的问题
①State Actions Mutations都是对象数据类型,他们三个都是由store统一管理
②我们要实现在任何组件中都可以调用dispatch,commit这两个api,但是这两个api都是store提供的,所以我们需要所有的组件实例都可以看到store

4.搭建vuex环境

注意:
vue2中要使用vuex的3版本
vue3中要使用vuex的4版本

npm i vuex //安装最新版本
npm i vuex@3  //安装3版本

4.1配置vuex

注意:由于vue-cli的执行机制,mainjs中会先执行import(不管import在mainjs的哪个位置)的内容,然后执行i别的
vue实例中有了store,那么vue组件的实例中也就有了store

					创建store/index.js
//该文件用于创建Vuex中最为核心的store
import Vue from 'vue'
//引入Vuex
import Vuex from 'vuex'
//应用Vuex插件
Vue.use(Vuex)

//准备actions——用于响应组件中的动作
const actions = {}
//准备mutations——用于操作数据(state)
const mutations = {}
//准备state——用于存储数据
const state = {}

//创建并暴露store
export default new Vuex.Store({
    actions, //实际上是 actions:actions 但是重名了 可以简写
    mutations,
    state,
})
				main.js中只需要引入store即可
//引入Vue
import Vue from 'vue'
//引入App
import App from './App.vue'
//引入插件
import vueResource from 'vue-resource'
//引入store
import store from './store'

//关闭Vue的生产提示
Vue.config.productionTip = false
//使用插件
Vue.use(vueResource)

//创建vm
new Vue({
	el:'#app',
	render: h => h(App),
	store,
	beforeCreate() {
		Vue.prototype.$bus = this
	}
})

5.求和案例

5.1不使用vuex

在这里插入图片描述

<template>
	<div>
		<h1>当前求和为:{{sum}}</h1>
		<select v-model.number="n">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
		<button @click="increment">+</button>
		<button @click="decrement">-</button>
		<button @click="incrementOdd">当前求和为奇数再加</button>
		<button @click="incrementWait">等一等再加</button>
	</div>
</template>

<script>
	export default {
		name:'Count',
		data() {
			return {
				n:1, //用户选择的数字
				sum:0 //当前的和
			}
		},
		methods: {
			increment(){
				this.sum += this.n
			},
			decrement(){
				this.sum -= this.n
			},
			incrementOdd(){
				if(this.sum % 2){
					this.sum += this.n
				}
			},
			incrementWait(){
				setTimeout(()=>{
					this.sum += this.n
				},500)
			},
		},
	}
</script>

<style lang="css">
	button{
		margin-left: 5px;
	}
</style>

5.2使用vuex

注意:
①store/index.js中是核心文件,actions中用来响应组件的动作,mustations用来操作数据(state),state用来保存数据
②在actions的函数中接收两个参数,一个是上下文context(他保存着一些actions中要经常使用的信息,如commit,dispatch,state),另外一个是value(比如本案例中的n值)
mutations中的函数也接受两个参数,第一个是state,第二个是value值
③actions中可以用来处理一些逻辑操作,比如本案例中判断sum是偶数还是奇数,然后进行操作;当不需要这些逻辑操作的时候,可以直接在组件中,直接去找mutations,不经过actions
④组件可以调用dispatch来联系actions;组件/actions可以使用commit来联系mutations
⑤actions中的函数常常是小写的;mutations中的函数常常是大写的;res:mutations才是最大的,只有他可以操作数据state
⑥在store/index.js中引入Vue Vuex,在最后暴露的时候,Vuex.Store ,每一个vuex的核心应用就是store(仓库);在mainjs中引入store(引入new的这个vuex的实例即可)即可;
⑦在vue实例中添加上store这个属性之后,vue实例(vm)和vue组件的实例(vc)上都可以发现$store这个属性

在这里插入图片描述
在这里插入图片描述

						store/index.js
//该文件用于创建Vuex中最为核心的store
import Vue from 'vue'
//引入Vuex
import Vuex from 'vuex'
//应用Vuex插件
Vue.use(Vuex)

//准备actions——用于响应组件中的动作
const actions = {    //context上下文 包含我们在actions中要用的全部的信息 如dispatch commit
        /* jia(context,value){    
        	console.log('actions中的jia被调用了')
        	context.commit('JIA',value)   //这里面写大写JIA 是为了区别actions中的和Mutations中的
        },
        jian(context,value){
        	console.log('actions中的jian被调用了')
        	context.commit('JIAN',value)
        }, */
        jiaOdd(context, value) {
            console.log('actions中的jiaOdd被调用了')
            if (context.state.sum % 2) {
                context.commit('JIA', value)
            }
        },
        jiaWait(context, value) {
            console.log('actions中的jiaWait被调用了')
            setTimeout(() => {
                context.commit('JIA', value)
            }, 500)
        }
    }
    //准备mutations——用于操作数据(state)
const mutations = {
        JIA(state, value) {
            console.log('mutations中的JIA被调用了')
            state.sum += value
        },
        JIAN(state, value) {
            console.log('mutations中的JIAN被调用了')
            state.sum -= value
        }
    }
    //准备state——用于存储数据
const state = {
    sum: 0 //当前的和  可以算作是默认值/初始值
}

//创建并暴露store
export default new Vuex.Store({
    actions, //实际上是 actions:actions 但是重名了 可以简写
    mutations,
    state,
})
							main.js
//引入Vue
import Vue from 'vue'
//引入App
import App from './App.vue'
//引入插件
import vueResource from 'vue-resource'
//引入store
import store from './store'

//关闭Vue的生产提示
Vue.config.productionTip = false
//使用插件
Vue.use(vueResource)

//创建vm
new Vue({
	el:'#app',
	render: h => h(App),
	store,
	beforeCreate() {
		Vue.prototype.$bus = this
	}
})
					component/Count.vue
<template>
	<div>
		<h1>当前求和为:{{$store.state.sum}}</h1>
		<select v-model.number="n">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
		<button @click="increment">+</button>
		<button @click="decrement">-</button>
		<button @click="incrementOdd">当前求和为奇数再加</button>
		<button @click="incrementWait">等一等再加</button>
	</div>
</template>

<script>
	export default {
		name:'Count',
		data() {
			return {
				n:1, //用户选择的数字
			}
		},
		methods: {
			increment(){
				this.$store.commit('JIA',this.n)  //由于actions中没有任何逻辑处理,vc直接和Mutations进行对话
			},
			decrement(){
				this.$store.commit('JIAN',this.n)
			},
			incrementOdd(){
				this.$store.dispatch('jiaOdd',this.n)
			},
			incrementWait(){
				this.$store.dispatch('jiaWait',this.n)
			},
		},
		mounted() {
			console.log('Count',this)
		},
	}
</script>

<style lang="css">
	button{
		margin-left: 5px;
	}
</style>

5.3使用vue开发者工具

在这里插入图片描述
从这里可以看出Devtools只会和mutations进行联系

6.store中的其他属性 getters

getters将state中的数据进行加工
在这里插入图片描述

7.mapState、mapGetters

map 是映射的意思,帮我们生成了原来我们手写的计算属性
//借助mapState生成计算属性,从state中读取数据。(对象写法)
…mapState({he:‘sum’,xuexiao:‘school’,xueke:‘subject’}),
//借助mapState生成计算属性,从state中读取数据。(数组写法)
…mapState([‘sum’,‘school’,‘subject’]), //展开运算符 这里要展开的原因:mapState是对象,computed也是对象,

<template>
	<div>
		<h1>当前求和为:{{sum}}</h1>
		<h3>当前求和放大10倍为:{{bigSum}}</h3>
		<h3>我在{{school}},学习{{subject}}</h3>
		<select v-model.number="n">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
		<button @click="increment">+</button>
		<button @click="decrement">-</button>
		<button @click="incrementOdd">当前求和为奇数再加</button>
		<button @click="incrementWait">等一等再加</button>
	</div>
</template>

<script>
	import {mapState,mapGetters} from 'vuex'
	export default {
		name:'Count',
		data() {
			return {
				n:1, //用户选择的数字
			}
		},
		computed:{
			//靠程序员自己亲自去写计算属性
			/* sum(){
				return this.$store.state.sum
			},
			school(){
				return this.$store.state.school
			},
			subject(){
				return this.$store.state.subject
			}, */

			//借助mapState生成计算属性,从state中读取数据。(对象写法)
			// ...mapState({he:'sum',xuexiao:'school',xueke:'subject'}),

			//借助mapState生成计算属性,从state中读取数据。(数组写法)
			...mapState(['sum','school','subject']), //展开运算符 这里要展开的原因:mapState是对象,computed也是对象,
			//对象里面不能写对象,使用展开运算符之后,相当于将sum school subject这些属性放到了computed这个对象中
			//

			/* ******************************************************************** */

			/* bigSum(){
				return this.$store.getters.bigSum
			}, */

			//借助mapGetters生成计算属性,从getters中读取数据。(对象写法)
			// ...mapGetters({bigSum:'bigSum'})
			
			//借助mapGetters生成计算属性,从getters中读取数据。(数组写法)
			...mapGetters(['bigSum'])

		},
		methods: {
			increment(){
				this.$store.commit('JIA',this.n)
			},
			decrement(){
				this.$store.commit('JIAN',this.n)
			},
			incrementOdd(){
				this.$store.dispatch('jiaOdd',this.n)
			},
			incrementWait(){
				this.$store.dispatch('jiaWait',this.n)
			},
		},
		mounted() {
			const x = mapState({he:'sum',xuexiao:'school',xueke:'subject'})
			console.log(x)
		},
	}
</script>

<style lang="css">
	button{
		margin-left: 5px;
	}
</style>

8.mapActions、mapMutations

注意:如果mapActions或者mapMutations需要传递参数,那么绑定事件的时候要传递好参数,否则参数是事件对象

<template>
	<div>
		<h1>当前求和为:{{sum}}</h1>
		<h3>当前求和放大10倍为:{{bigSum}}</h3>
		<h3>我在{{school}},学习{{subject}}</h3>
		<select v-model.number="n">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
		<button @click="increment(n)">+</button>
		<button @click="decrement(n)">-</button>
		<button @click="incrementOdd(n)">当前求和为奇数再加</button>
		<button @click="incrementWait(n)">等一等再加</button>
	</div>
</template>

<script>
	import {mapState,mapGetters,mapMutations,mapActions} from 'vuex'
	export default {
		name:'Count',
		data() {
			return {
				n:1, //用户选择的数字
			}
		},
		computed:{
			//借助mapState生成计算属性,从state中读取数据。(对象写法)
			// ...mapState({he:'sum',xuexiao:'school',xueke:'subject'}),

			//借助mapState生成计算属性,从state中读取数据。(数组写法)
			...mapState(['sum','school','subject']),

			/* ******************************************************************** */

			//借助mapGetters生成计算属性,从getters中读取数据。(对象写法)
			// ...mapGetters({bigSum:'bigSum'})
			
			//借助mapGetters生成计算属性,从getters中读取数据。(数组写法)
			...mapGetters(['bigSum'])

		},
		methods: {
			//程序员亲自写方法
			/* increment(){
				this.$store.commit('JIA',this.n)
			},
			decrement(){
				this.$store.commit('JIAN',this.n)
			}, */

			//借助mapMutations生成对应的方法,方法中会调用commit去联系mutations(对象写法)
			...mapMutations({increment:'JIA',decrement:'JIAN'}),

			//借助mapMutations生成对应的方法,方法中会调用commit去联系mutations(数组写法)
			// ...mapMutations(['JIA','JIAN']),

			/* ************************************************* */

			//程序员亲自写方法
			/* incrementOdd(){
				this.$store.dispatch('jiaOdd',this.n)
			},
			incrementWait(){
				this.$store.dispatch('jiaWait',this.n)
			}, */

			//借助mapActions生成对应的方法,方法中会调用dispatch去联系actions(对象写法)
			...mapActions({incrementOdd:'jiaOdd',incrementWait:'jiaWait'})

			//借助mapActions生成对应的方法,方法中会调用dispatch去联系actions(数组写法)
			// ...mapActions(['jiaOdd','jiaWait'])
		},
		mounted() {
			const x = mapState({he:'sum',xuexiao:'school',xueke:'subject'})
			console.log(x)
		},
	}
</script>

<style lang="css">
	button{
		margin-left: 5px;
	}
</style>

9.vuex模块化①

							Count.vue
<template>
	<div>
		<h1>当前求和为:{{sum}}</h1>
		<h3>当前求和放大10倍为:{{bigSum}}</h3>
		<h3>我在{{school}},学习{{subject}}</h3>
		<h3 style="color:red">Person组件的总人数是:{{personList.length}}</h3>
		<select v-model.number="n">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
		<button @click="increment(n)">+</button>
		<button @click="decrement(n)">-</button>
		<button @click="incrementOdd(n)">当前求和为奇数再加</button>
		<button @click="incrementWait(n)">等一等再加</button>
	</div>
</template>

<script>
	import {mapState,mapGetters,mapMutations,mapActions} from 'vuex'
	export default {
		name:'Count',
		data() {
			return {
				n:1, //用户选择的数字
			}
		},
		computed:{
			//借助mapState生成计算属性,从state中读取数据。(数组写法)
			...mapState('countAbout',['sum','school','subject']),
			...mapState('personAbout',['personList']),
			//借助mapGetters生成计算属性,从getters中读取数据。(数组写法)
			...mapGetters('countAbout',['bigSum'])
		},
		methods: {
			//借助mapMutations生成对应的方法,方法中会调用commit去联系mutations(对象写法)
			...mapMutations('countAbout',{increment:'JIA',decrement:'JIAN'}),
			//借助mapActions生成对应的方法,方法中会调用dispatch去联系actions(对象写法)
			...mapActions('countAbout',{incrementOdd:'jiaOdd',incrementWait:'jiaWait'})
		},
		mounted() {
			console.log(this.$store)
		},
	}
</script>

<style lang="css">
	button{
		margin-left: 5px;
	}
</style>

					store/index.js
//该文件用于创建Vuex中最为核心的store
import Vue from 'vue'
//引入Vuex
import Vuex from 'vuex'
//应用Vuex插件
Vue.use(Vuex)

//求和相关配置
const countOptions = {
	namespaced:true,
	actions:{
		jiaOdd(context,value){
			console.log('actions中的jiaOdd被调用了')
			if(context.state.sum % 2){
				context.commit('JIA',value)
			}
		},
		jiaWait(context,value){
			console.log('actions中的jiaWait被调用了')
			setTimeout(()=>{
				context.commit('JIA',value)
			},500)
		}
	},
	mutations:{
		JIA(state,value){
			console.log('mutations中的JIA被调用了')
			state.sum += value
		},
		JIAN(state,value){
			console.log('mutations中的JIAN被调用了')
			state.sum -= value
		},
	},
	state:{
		sum:0, //当前的和
		school:'尚硅谷',
		subject:'前端',
	},
	getters:{
		bigSum(state){   //这里拿到的state是自己的state,不是总的state
			return state.sum*10
		}
	},
	
}

//人员管理相关配置
const personOptions = {
	namespaced:true,
	actions:{
		addPersonWang(context,value){
			if(value.name.indexOf('王') === 0){
				context.commit('ADD_PERSON',value)
			}else{
				alert('添加的人必须姓王!')
			}
		},
		addPersonServer(context){
			axios.get('https://api.uixsj.cn/hitokoto/get?type=social').then(
				response => {
					context.commit('ADD_PERSON',{id:nanoid(),name:response.data})
				},
				error => {
					alert(error.message)
				}
			)
		}
	},
	mutations:{
		ADD_PERSON(state,value){
			console.log('mutations中的ADD_PERSON被调用了')
			state.personList.unshift(value)
		}
	},
	state:{
		personList:[
			{id:'001',name:'张三'}
		]
	},
	getters:{
		firstPersonName(state){
			return state.personList[0].name
		}
	},
}

//创建并暴露store
export default new Vuex.Store({
	modules:{
		countAbout:countOptions,
		personAbout:personOptions
	}
})

10.vuex模块化② 将Count和Person写到单独的文件夹

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

						目录如下

在这里插入图片描述

						main.js
//引入Vue
import Vue from 'vue'
//引入App
import App from './App.vue'
//引入插件
import vueResource from 'vue-resource'
//引入store
import store from './store'

//关闭Vue的生产提示
Vue.config.productionTip = false
//使用插件
Vue.use(vueResource)

//创建vm
new Vue({
	el:'#app',
	render: h => h(App),
	store,
	beforeCreate() {
		Vue.prototype.$bus = this
	}
})

						APP.vue			
<template>
	<div>
		<Count/>
		<hr>
		<Person/>
	</div>
</template>

<script>
	import Count from './components/Count'
	import Person from './components/Person'

	export default {
		name:'App',
		components:{Count,Person},
		mounted() {
			// console.log('App',this)
		},
	}
</script>
						Count.vue
<template>
	<div>
		<h1>当前求和为:{{sum}}</h1>
		<h3>当前求和放大10倍为:{{bigSum}}</h3>
		<h3>我在{{school}},学习{{subject}}</h3>
		<h3 style="color:red">Person组件的总人数是:{{personList.length}}</h3>
		<select v-model.number="n">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
		<button @click="increment(n)">+</button>
		<button @click="decrement(n)">-</button>
		<button @click="incrementOdd(n)">当前求和为奇数再加</button>
		<button @click="incrementWait(n)">等一等再加</button>
	</div>
</template>

<script>
	import {mapState,mapGetters,mapMutations,mapActions} from 'vuex'
	export default {
		name:'Count',
		data() {
			return {
				n:1, //用户选择的数字
			}
		},
		computed:{
			//借助mapState生成计算属性,从state中读取数据。(数组写法)
			...mapState('countAbout',['sum','school','subject']),
			...mapState('personAbout',['personList']),
			//借助mapGetters生成计算属性,从getters中读取数据。(数组写法)
			...mapGetters('countAbout',['bigSum'])
		},
		methods: {
			//借助mapMutations生成对应的方法,方法中会调用commit去联系mutations(对象写法)
			...mapMutations('countAbout',{increment:'JIA',decrement:'JIAN'}),
			//借助mapActions生成对应的方法,方法中会调用dispatch去联系actions(对象写法)
			...mapActions('countAbout',{incrementOdd:'jiaOdd',incrementWait:'jiaWait'})
		},
		mounted() {
			console.log(this.$store)
		},
	}
</script>

<style lang="css">
	button{
		margin-left: 5px;
	}
</style>
						Person.vue
<template>
	<div>
		<h1>人员列表</h1>
		<h3 style="color:red">Count组件求和为:{{sum}}</h3>
		<h3>列表中第一个人的名字是:{{firstPersonName}}</h3>
		<input type="text" placeholder="请输入名字" v-model="name">
		<button @click="add">添加</button>
		<button @click="addWang">添加一个姓王的人</button>
		<button @click="addPersonServer">添加一个人,名字随机</button>
		<ul>
			<li v-for="p in personList" :key="p.id">{{p.name}}</li>
		</ul>
	</div>
</template>

<script>
	import {nanoid} from 'nanoid'
	export default {
		name:'Person',
		data() {
			return {
				name:''
			}
		},
		computed:{
			personList(){
				return this.$store.state.personAbout.personList
			},
			sum(){
				return this.$store.state.countAbout.sum
			},
			firstPersonName(){
				return this.$store.getters['personAbout/firstPersonName']
			}
		},
		methods: {
			add(){
				const personObj = {id:nanoid(),name:this.name}
				this.$store.commit('personAbout/ADD_PERSON',personObj)
				this.name = ''
			},
			addWang(){
				const personObj = {id:nanoid(),name:this.name}
				this.$store.dispatch('personAbout/addPersonWang',personObj)
				this.name = ''
			},
			addPersonServer(){
				this.$store.dispatch('personAbout/addPersonServer')
			}
		},
		mounted(){
			console.log(this.$store)
		}
	}
</script>
				store/index.js
//该文件用于创建Vuex中最为核心的store
import Vue from 'vue'
//引入Vuex
import Vuex from 'vuex'
import countOptions from './count'
import personOptions from './person'
//应用Vuex插件
Vue.use(Vuex)

//创建并暴露store
export default new Vuex.Store({
	modules:{
		countAbout:countOptions,
		personAbout:personOptions
	}
})
					store/count.js
//求和相关的配置
export default {
	namespaced:true,
	actions:{
		jiaOdd(context,value){
			console.log('actions中的jiaOdd被调用了')
			if(context.state.sum % 2){
				context.commit('JIA',value)
			}
		},
		jiaWait(context,value){
			console.log('actions中的jiaWait被调用了')
			setTimeout(()=>{
				context.commit('JIA',value)
			},500)
		}
	},
	mutations:{
		JIA(state,value){
			console.log('mutations中的JIA被调用了')
			state.sum += value
		},
		JIAN(state,value){
			console.log('mutations中的JIAN被调用了')
			state.sum -= value
		},
	},
	state:{
		sum:0, //当前的和
		school:'尚硅谷',
		subject:'前端',
	},
	getters:{
		bigSum(state){
			return state.sum*10
		}
	},
}
					store/person.js

nanoid是什么以及安装方式

//人员管理相关的配置
import axios from 'axios'
import { nanoid } from 'nanoid'
export default {
    namespaced: true,
    actions: {
        addPersonWang(context, value) {
            if (value.name.indexOf('王') === 0) {
                context.commit('ADD_PERSON', value)
            } else {
                alert('添加的人必须姓王!')
            }
        },
        addPersonServer(context) {
        //https://api.uixsj.cn/hitokoto/get?type=social这是随机生成语录的api   nanoid 这是随机id
            axios.get('https://api.uixsj.cn/hitokoto/get?type=social').then(
                response => {
                    context.commit('ADD_PERSON', { id: nanoid(), name: response.data })
                },
                error => {
                    alert(error.message)
                }
            )
        }
    },
    mutations: {
        ADD_PERSON(state, value) {
            console.log('mutations中的ADD_PERSON被调用了', value)
            state.personList.unshift(value)
        }
    },
    state: {
        personList: [
            { id: '001', name: '张三' }
        ]
    },
    getters: {
        firstPersonName(state) {
            return state.personList[0].name
        }
    },
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/586864.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

和ChatGPT关于Swing music的一场对话(下篇)

昨天无意中刷到的系统推送的文章 点进去一看&#xff0c;原来介绍的就是老苏为了抛砖引玉编的 Swing music 的镜像&#xff0c;动作真是快啊。 坦白的说&#xff0c;文章比老苏写的好&#xff0c;所以让我纠结了好一阵子&#xff0c;本文我是发呢还是不发呢&#xff1f;不过似…

jQuery实现响应式瀑布流效果(jQuery+flex)

瀑布流原理&#xff1a;是一种常见的网页布局方式&#xff0c;它的特点是将内容以多列的形式呈现&#xff0c;每一列的内容高度不固定&#xff0c;根据内容的大小自适应调整&#xff0c;从而形成了像瀑布一样的流动效果。 瀑布流的实现原理涉及到数据加载、布局设计、图片加载和…

ML算法——KNN随笔【全国科技工作者日创作】【机器学习】

9、K-Nearest Neighbors (KNN) 9.1、理论部分 K最邻近算法 把一个物体表示成向量【特征工程】,且 KNN 需要考虑 【特征缩放】。标记每个物体的标签计算两个物体之间的距离/相似度选择合适的 K 未知点的判断基于已知点的距离&#xff0c;选出最近的K个点&#xff0c;投票选出…

pyjail初了解

前言 最近在各种比赛Misc方向都能多多小小看到Python jail题&#xff0c;通过eval或者exec等函数执行Python的代码获取shell&#xff0c;实现Python逃逸&#xff0c;但是我不是太会&#xff0c;因此找点题目做一下&#xff0c;总结一下。 常用Python的魔术方法 _init_:用于P…

chatgpt赋能python:Python中小数点保留的几种方法

Python中小数点保留的几种方法 作为一名Python工程师&#xff0c;我们经常需要对数字进行处理。在处理时&#xff0c;我们需要将数字进行格式化&#xff0c;例如保留小数点后几位或添加千位分隔符等。其中&#xff0c;保留小数点后几位是比较常见的需求。本文将介绍Python中小…

chatgpt赋能Python-python中怎么安装aip

概述 在现代的SEO中&#xff0c;使用机器学习和自然语言处理的API来分析关键字和网页内容已经成为一个普遍的实践。Google API是其中最受欢迎的一个&#xff0c;因为它可以提供多种功能&#xff0c;包括分析关键字、分析文本和图像识别等。 Python作为一种优秀的脚本语言&…

Linux Apache 配置与应用 【虚拟主机 连接保持 日志分割 分析系统 优化网页】

--------构建虚拟 Web 主机-------- 虚拟Web主机指的是在同一台服务器中运行多个Web站点&#xff0c;其中每一个站点实际上并不独立占用整个服务器&#xff0c;因此被称为“虚拟”Web 主机。通过虚拟 Web 主机服务可以充分利用服务器的硬件资源&#xff0c;从而大大降低网站构建…

《深入理解计算机系统(CSAPP)》第8章 异常控制流 - 学习笔记

写在前面的话&#xff1a;此系列文章为笔者学习CSAPP时的个人笔记&#xff0c;分享出来与大家学习交流&#xff0c;目录大体与《深入理解计算机系统》书本一致。因是初次预习时写的笔记&#xff0c;在复习回看时发现部分内容存在一些小问题&#xff0c;因时间紧张来不及再次整理…

chatgpt赋能python:Python合并函数:一个简单但有用的工具

Python合并函数&#xff1a;一个简单但有用的工具 Python是一种优雅而强大的编程语言&#xff0c;拥有许多内置的函数和库&#xff0c;可以让编程变得更加简单和高效。其中&#xff0c;合并函数是一个非常有用的工具&#xff0c;它可以让我们快速而灵活地合并和处理数据。 什…

5月30日第壹简报,星期二,农历四月十二

5月30日第壹简报&#xff0c;星期二&#xff0c;农历四月十二坚持阅读&#xff0c;静待花开1. 比亚迪&#xff1a;自主研发了常压油箱的燃油蒸汽排放控制技术&#xff0c;能符合蒸发排放法规标准&#xff0c; 愿与所有同行共享核心技术专利。2. 中国计划2030年前实现首次登月&a…

chatgpt赋能python:Python中升序和降序排序:什么是升序和降序以及如何使用Python进行排序

Python中升序和降序排序&#xff1a;什么是升序和降序以及如何使用Python进行排序 介绍 Python是一种强大的编程语言&#xff0c;可以用来处理各种类型的数据。其中包括对数据进行排序&#xff0c;Python具有方便且易于使用的排序功能。在Python中&#xff0c;可以使用升序和…

chatgpt赋能python:Python中可迭代对象的介绍

Python中可迭代对象的介绍 Python是一种高级编程语言&#xff0c;它具有简单易学、可读性强、功能强大等特点&#xff0c;成为了数据科学、机器学习、Web开发等领域的热门选择。Python中有很多重要的概念和功能&#xff0c;其中之一就是支持可迭代对象的概念。 在Python中&am…

chatgpt赋能python:Python中如何生成表格

Python中如何生成表格 在数据分析和处理中&#xff0c;表格是一种常见的数据格式&#xff0c;并且在不同的场景下都有着不同的用途。Python作为一种高效的编程语言&#xff0c;可以帮助我们轻松地生成和操作表格数据。在本文中&#xff0c;我们将介绍Python中生成表格的方法&a…

IDEA控制台tomcat 乱码

问题 IDEA控制台tomcat 乱码 详细问题 项目部署至tomcat上&#xff0c;启动tomcat&#xff0c;IDEA控制台终端Server日志&#xff0c;Tomcat Localhost日志&#xff0c;Tomcat Catalina日志乱码 Server日志 D:\tomcat9\bin\catalina.bat run [2023-05-29 11:20:24,521] Art…

【Linux】在Ubuntu中卸载、下载mysql以及如何检查mysql是否卸载成功

介绍 这里是小编成长之路的历程&#xff0c;也是小编的学习之路。希望和各位大佬们一起成长&#xff01; 以下为小编最喜欢的两句话&#xff1a; 要有最朴素的生活和最遥远的梦想&#xff0c;即使明天天寒地冻&#xff0c;山高水远&#xff0c;路远马亡。 一个人为什么要努力&a…

5.30黄金空头能否延续?今日多空如何布局?

近期有哪些消息面影响黄金走势&#xff1f;今日黄金多空该如何研判&#xff1f; ​黄金消息面解析&#xff1a;周一(5月29日)进入欧市盘中&#xff0c;对美国周末达成债务上限协议的乐观情绪推动风险情绪回升&#xff0c;与此同时&#xff0c;上周公布的美国PCE数据让美联储难…

ChatGPT Sorry, you have been blocked(抱歉,您已被屏蔽)的解决方法

最近在使用 ChatGPT 时大家遇到的最多的问题就是 Sorry, you have been blocked&#xff08;抱歉&#xff0c;您已被屏蔽&#xff09;了&#xff0c;之前的 Access denied 似乎都不常见了&#xff0c;今天老王就分享下这个问题的原因和解决方法。 一、ChatGPT 被屏蔽 blocked …

汇编调试及学习

汇编调试 打印寄存器的值 打印内存地址 打印8字节&#xff0c;就是64位 打印格式 是从低位取过来的 b 字节 h 双字节 w四字节 g八字节 前变基 后变基 。 后变基这个变基会发生变化的。前变基变基不会发生变化需要用&#xff01;号。 前变基 &#xff0c; 加了&#xff0…

【Springcloud】RabbitMQ入门

文章目录 一、同步通讯与异步通讯1、同步调用的优缺点2、异步调用的优缺点 二、RabbitMQ1、MQ消息队列2、RabbitMQ的安装3、RabbitMQ的结构和概念4、RabbitMQ的消息模型5、入门案例 一、同步通讯与异步通讯 同步通讯就像打视频&#xff0c;两边可以实时得到相关信息。异步通讯…

打开复制过去的virtualbox文件之后,在打开时出现只有logs文件的解决方法

文章目录 前言 问题一 打开方式 注意事项 问题二 解决方法 总结 前言 打开复制过去的virtualbox文件之后&#xff0c;在打开时出现只有logs文件的解决方法 问题一 virtualbox虚拟机拷贝到其他电脑上面如何打开&#xff1f; 打开方式 将 VirtualBox 虚拟机拷贝到其他…