Vue2 基礎十Vuex

代碼下載

Vuex 概述

組件之間共享數據的方式:

  • 父組件向子組件傳值,是以屬性的形式綁定值到子組件(v-bind),然后子組件用屬性props接收。
  • 子組件向父組件傳值,子組件用 $emit() 自定義事件,父組件用v-on監聽子組件的事件。
  • 兄弟組件的傳值,通過事件中心傳遞數據,提供事件中心 var hub = new Vue(),傳遞數據方通過一個事件觸發 hub.$emit(方法名,傳遞的數據),接收數據方通過在 mounted(){} 鉤子中 觸發 hub.$on(方法名, 傳遞的數據)

Vuex是實現組件全局狀態(數據)管理的一種機制,可以方便的實現組件之間的數據共享。使用Vuex管理數據的好處:

  • 能夠在vuex中集中管理共享的數據,便于開發和后期進行維護
  • 能夠高效的實現組件之間的數據共享,提高開發效率
  • 存儲在vuex中的數據是響應式的,當數據發生改變時,頁面中的數據也會同步更新

一般情況下,只有組件之間共享的數據,才有必要存儲到 vuex 中;對于組件中的私有數據,依舊存儲在組件自身的 data 中即可。

Vuex 簡單使用

1、安裝 vuex 依賴包

npm install vuex --save

2、導入 vuex 包

import Vuex from 'vuex'
Vue.use(Vuex)

3、創建 store 對象

const store = new Vuex.Store({// state 中存放的就是全局共享的數據state: { count: 0 }
})

4、 將 store 對象掛載到 vue 實例中

new Vue({el: '#app',render: h => h(app),// 將創建的共享數據對象,掛載到 Vue 實例中// 所有的組件,就可以直接從 store 中獲取全局的數據了store
})

在使用 vue 腳手架創建項目時,可以在功能選項中直接開啟使用 Vuex 的開關。

Vuex 的核心概念

Vuex 中的主要核心概念如下:StateMutationActionGetter

State

State 提供唯一的公共數據源,所有共享的數據都要統一放到 Store 的 State 中進行存儲。

// 創建store數據源,提供唯一公共數據
const store = new Vuex.Store({state: { count: 0 }
})

組件訪問 State 中數據的第一種方式:this.$store.state.全局數據名稱

組件訪問 State 中數據的第二種方式:
1、從 vuex 中按需導入 mapState 函數:

import { mapState } from 'vuex'

2、通過剛才導入的 mapState 函數,將當前組件需要的全局數據,映射為當前組件的 computed 計算屬性:

computed: {...mapState(['count'])
}

Mutation

Mutation 用于變更 Store中 的數據。

注意:只能通過 mutation 變更 Store 數據,不可以直接操作 Store 中的數據。通過這種方式雖然操作起來稍微繁瑣一些,但是可以集中監控所有數據的變化。

定義 Mutation,也可以在觸發 mutations 時傳遞參數:

export default new Vuex.Store({state: {count: 0},mutations: {add(state) {state.count++},addN(state, step) {state.count += step}}
})

組件觸發 mutations 的第一種方式:this.$store.commit('add')this.$store.commit('add', 3)

組件觸發 mutations 的第二種方式:
1、從 vuex 中按需導入 mapMutations 函數

import { mapMutations } from 'vuex'

2、通過剛才導入的 mapMutations 函數,將需要的 mutations 函數,映射為當前組件的 methods 方法

methods: {...mapMutations(['add', 'addN'])
}

Action

Action 用于處理異步任務。如果通過異步操作變更數據,必須通過 Action,而不能使用 Mutation,但是在 Action 中還是要通過觸發 Mutation 的方式間接變更數據。

定義 Action,也可以在觸發 actions 異步任務時攜帶參數:

  actions: {addAsync(context) {setTimeout(() => {context.commit('add')}, 1000);},addNAsync(context, step) {setTimeout(() => {context.commit('addN', step)}, 1000);}}

觸發 actions 的第一種方式:this.$store.dispatch('addSsync')this.$store.dispatch('addAsync', 3)

觸發 actions 的第二種方式:
1、從 vuex 中按需導入 mapActions 函數

import { mapActions } from 'vuex'

2、通過剛才導入的 mapActions 函數,將需要的 actions 函數,映射為當前組件的 methods 方法:

methods: {...mapActions(['addASync', 'addNASync'])
}

Getter

Getter 用于對 Store 中的數據進行加工處理形成新的數據,類似 Vue 的計算屬性。Store 中數據發生變化,Getter 的數據也會跟著變化。

定義 Getter:

export default new Vuex.Store({state: {count: 0},getters: {showNum(state) {return '當前最新數量是:' + state.count}}
}

使用 getters 的第一種方式:this.$store.getters.showNum

使用 getters 的第二種方式:
1、從 vuex 中按需導入 mapGetters 函數

import { mapGetters } from 'vuex'

2、通過剛才導入的 mapGetters 函數,將需要的 getters 函數,映射為當前組件的 computed 計算屬性:

computed: {...mapGetters(['showNum'])
}

示例

1、在 store > index.js 中創建 store 對象,并定義相應的 state、mutations、actions、getters:

import Vue from 'vue'
import Vuex from 'vuex'Vue.use(Vuex)export default new Vuex.Store({state: {count: 0},getters: {showNum(state) {return '當前最新數量是:' + state.count}},mutations: {add(state) {state.count++},addN(state, step) {state.count += step},sub(state) {state.count--},subN(state, step) {state.count -= step}},actions: {addAsync(context) {setTimeout(() => {context.commit('add')}, 1000);},addNAsync(context, step) {setTimeout(() => {context.commit('addN', step)}, 1000);},subAsync(context) {setTimeout(() => {context.commit('sub')}, 1000);},subNAsync(context, step) {setTimeout(() => {context.commit('subN', step)}, 1000);}},modules: {}
})

2、在 components > addition.vue 文件中,運用第一種方法使用 state、mutations、actions、getters:

<template><div><h3>計算結果:{{$store.state.count}}</h3><button @click="btnHandle1">+1</button><div><input type="number" placeholder="請輸入數值" v-model.number="addNum"><button @click="btnHandleN">+{{addNum}}</button></div><button @click="btnHandle1Async">+1 async</button><div><input type="number" placeholder="請輸入數值" v-model.number="addNumAsync"><button @click="btnHandleNAsync">+{{addNumAsync}}</button></div><h3>{{$store.getters.showNum}}</h3></div>
</template><script>
export default {data() {return {addNum: 2,addNumAsync: 3}},methods: {btnHandle1() {this.$store.commit('add')},btnHandleN() {this.$store.commit('addN', this.addNum)},btnHandle1Async() {this.$store.dispatch('addAsync')},btnHandleNAsync() {this.$store.dispatch('addNAsync', this.addNumAsync)}}
}
</script>

3、在 components > subtraction.vue 文件中,運用第二種方法使用 state、mutations、actions、getters:

<template><div><h3>計算結果:{{count}}</h3><button @click="btnHandle1">-1</button><div><input type="number" placeholder="請輸入數值" v-model.number="subNum"><button @click="btnHandleN">-{{subNum}}</button></div><button @click="subAsync">-1 async</button><div><input type="number" placeholder="請輸入數值" v-model.number="subNumAsync"><button @click="subNAsync(subNumAsync)">-{{subNumAsync}} async</button></div><h3>{{showNum}}</h3></div>
</template><script>
import { mapState, mapMutations, mapActions, mapGetters } from 'vuex';
export default {data() {return {subNum: 2,subNumAsync: 3}},computed: {...mapState(['count']),...mapGetters(['showNum'])},methods: {...mapMutations(['sub', 'subN']),btnHandle1() {this.sub()}, btnHandleN() {this.subN(this.subNum)},...mapActions(['subAsync', 'subNAsync'])}
}
</script>

Vuex 案例

項目初始化

1、通過 vue ui 命令打開可視化面板,創建新項目(略,這里使用的是和上面示例同一個項目)。

2、安裝依賴包:npm install axiosnpm install ant-design-vue@1.7.8,因為這里使用的 vue2.x,所以 ant-design-vue 版本使用1.7.8。

注意:需要在 package.json 文件中將 eslint-plugin-vue 版本改為7.0.0 "eslint-plugin-vue": "^7.0.0",否則會與 ant-design-vue 有版本沖突。

打開 main.js 導入并配置相應的組件庫:

// 1. 導入 ant-design-vue 組件庫
import Antd from 'ant-design-vue'
// 2. 導入組件庫的樣式表
import 'ant-design-vue/dist/antd.css'
// 3. 安裝組件庫
Vue.use(Antd)

3、實現 Todos 基本布局,在 components 文件夾中新建 toDoList.vue 文件,并實現布局代碼:

<template><div id="app"><a-input placeholder="請輸入任務" class="my_ipt" /><a-button type="primary">添加事項</a-button><a-list bordered :dataSource="list" class="dt_list"><a-list-item slot="renderItem" slot-scope="item"><!-- 復選框 --><a-checkbox>{{item.info}}</a-checkbox><!-- 刪除鏈接 --><a slot="actions">刪除</a></a-list-item><!-- footer區域 --><div slot="footer" class="footer"><!-- 未完成的任務個數 --><span>0條剩余</span><!-- 操作按鈕 --><a-button-group><a-button type="primary">全部</a-button><a-button>未完成</a-button><a-button>已完成</a-button></a-button-group><!-- 把已經完成的任務清空 --><a>清除已完成</a></div></a-list></div>
</template><script>
export default {name: 'app',data() {return {list: [{id: 0,info: 'Racing car sprays burning fuel into crowd.',done: false},{ id: 1, info: 'Japanese princess to wed commoner.', done: false },{id: 2,info: 'Australian walks 100km after outback crash.',done: false},{ id: 3, info: 'Man charged over missing wedding girl.', done: false },{ id: 4, info: 'Los Angeles battles huge wildfires.', done: false }]}}
}
</script><style scoped>
#app {padding: 10px;
}.my_ipt {width: 500px;margin-right: 10px;
}.dt_list {width: 500px;margin-top: 10px;
}.footer {display: flex;justify-content: space-between;align-items: center;
}
</style>

功能實現

動態加載任務列表數據

1、打開public文件夾,創建一個list.json文件,填充數據:

[{"id": 0,"info": "Racing car sprays burning fuel into crowd.","done": false},{"id": 1,"info": "Japanese princess to wed commoner.","done": false},{"id": 2,"info": "Australian walks 100km after outback crash.","done": false},{"id": 3,"info": "Man charged over missing wedding girl.","done": false},{"id": 4,"info": "Los Angeles battles huge wildfires.","done": false}
]

2、再接著打開 store/index.js,導入 axios 并在 actions 中添加 axios 請求 json 文件獲取數據的代碼,因為數據請求是異步的所以必須在 actions 中實現,如下:

import axios from 'axios'export default new Vuex.Store({state: {// 任務列表list: []},mutations: {initList(state, list) {state.list = list}},actions: {getList(context) {axios.get('/list.json').then(({ data }) => {console.log('data: ', data);context.commit('initList', data)})}}
})

3、打開 toDoList.vue 文件,將 store 中的數據獲取并展示:

<script>
import { mapState } from 'vuex'export default {data() {return {// list:[]}},created(){// console.log(this.$store);this.$store.dispatch('getList')},computed:{...mapState(['list'])}
}
</script>

文本框與store數據的雙向同步

1、在 store/index.js 文件的 state 中新增 inputValue: 'aaa' 字段,并在 mutations 中新增其修改方法 setInputValue

    // 設置 輸入值setInputValue(state, value) {console.log('value: ', value);state.inputValue = value}

2、在 toDoList.vue 文件的 computed 中映射 inputValue 計算方法:

  computed:{...mapState(['list', 'inputValue'])}

3、將 inputValue 計算方法綁定到 a-input 元素的 value 上。

4、為 a-input 元素綁定 change 事件方法 handleInputChange

    handleInputChange(e) {this.setInputValue(e.target.value)}

添加任務

1、在 store/index.js 文件 state 中新增 nextId: 5 字段,并在 mutations 中編寫 addItem:

    // 添加任務項addItem(state) {const item = {id: state.nextId,info: state.inputValue.trim(),done: false}state.list.push(item)state.nextId++state.inputValue = ''}

2、在 toDoList.vue 文件給“添加事項”按鈕綁定點擊事件,編寫處理函數:

    addItemToList() {console.log('iv: ', this.inputValue.trim());if (this.inputValue.trim().length <= 0) {return this.$message.warning('文本框內容不能為空!')}this.$store.commit('addItem')}

其他功能實現

store/index.js 文件代碼具體實現:

export default new Vuex.Store({state: {// 任務列表list: [],// 文本框內容inputValue: 'aaa',nextId: 5,viewKey: 'all'},getters: {infoList(state) {if (state.viewKey === 'all') {return state.list} else if (state.viewKey === 'undone') {return state.list.filter(item => !item.done)} else {return state.list.filter(item => item.done)}},unDoneLength(state) {return state.list.filter(item => !item.done).length}},mutations: {// 修改列表數據initList(state, list) {state.list = list},// 設置 輸入值setInputValue(state, value) {console.log('value: ', value);state.inputValue = value},// 添加任務項addItem(state) {const item = {id: state.nextId,info: state.inputValue.trim(),done: false}state.list.push(item)state.nextId++state.inputValue = ''},// 刪除任務項removeItem(state, id) {const index = state.list.findIndex(item => item.id === id)if (index !== -1) {state.list.splice(index, 1)}},// 更改任務完成狀態statusChange(state, params) {const index = state.list.findIndex(item => item.id === params.id)if (index !== -1) {state.list[index].done = params.done}},// 清除完成任務項clearDone(state) {state.list = state.list.filter(item => !item.done)},// 改版列表數據類型changeViewKey(state, key) {state.viewKey = key}},actions: {getList(context) {axios.get('/list.json').then(({ data }) => {console.log('data: ', data);context.commit('initList', data)})}}
})

toDoList.vue 文件具體實現:

<template><div><a-input placeholder="請輸入任務" class="my_ipt" :value="inputValue" @change="handleInputChange"/><a-button type="primary" @click="addItemToList">添加事項</a-button><a-list bordered :dataSource="infoList" class="dt_list" ><a-list-item slot="renderItem" slot-scope="item"><!-- 復選框 --><a-checkbox :checked="item.done" @change="cbStatusChange(item.id, $event)">{{item.info}}</a-checkbox><!-- 刪除鏈接 --><a slot="actions" @click="remoItemById(item.id)">刪除</a></a-list-item><!-- footer區域 --><div slot="footer" class="footer"><!-- 未完成的任務個數 --><span>{{unDoneLength}}條剩余</span><!-- 操作按鈕 --><a-button-group><a-button :type="viewKey === 'all' ? 'primary' : 'default'" @click="changeList('all')">全部</a-button><a-button :type="viewKey === 'undone' ? 'primary' : 'default'" @click="changeList('undone')">未完成</a-button><a-button :type="viewKey === 'done' ? 'primary' : 'default'" @click="changeList('done')">已完成</a-button></a-button-group><!-- 把已經完成的任務清空 --><a @click="clear">清除已完成</a></div></a-list></div>
</template><script>
import { mapState, mapMutations, mapGetters } from 'vuex'
export default {data() {return {}},created() {this.$store.dispatch('getList')},computed: {...mapState(['inputValue', 'viewKey']),...mapGetters(['unDoneLength', 'infoList'])},methods: {...mapMutations(['setInputValue']),handleInputChange(e) {this.setInputValue(e.target.value)},addItemToList() {console.log('iv: ', this.inputValue.trim());if (this.inputValue.trim().length <= 0) {return this.$message.warning('文本框內容不能為空!')}this.$store.commit('addItem')},// 根據 id 刪除對應的任務remoItemById(id) {this.$store.commit('removeItem', id)},cbStatusChange(id, e) {const params = {id,done: e.target.checked}console.log('chang params: ', params);this.$store.commit('statusChange', params)},// 清除已完成clear() {this.$store.commit('clearDone')},changeList(key) {console.log('changeList: ', key);this.$store.commit('changeViewKey', key)}}
}
</script>

1、刪除任務,通過 mutations 修改列表數據實現,詳細實現細節見上述代碼。

2、綁定復選框的選中狀態,同上。

3、修改任務的完成狀態,同上。

4、清除已完成的任務,同上。

5、任務列表數據的動態切換,同上。

6、統計未完成的任務的條數,通過 Getter 加工列表數實現,詳細實現細節見上述代碼

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/43447.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/43447.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/43447.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

JavaScript--local storage存儲的數組不可擴展的問題

數組擴展 問題解析解決辦法總結進一步擴展原因 問題 下列代碼中的points是從本地存儲中獲取到的數據&#xff0c;我想存儲到一個Map并且新增元素的時候報錯 let obj this.objectsManager._objects.get(obstacle.uuid);let points obj.track_points;this.dyObstacleTP.set(ob…

【大模型】大模型相關技術研究—微調

為什么要對大模型進行微調 1.成本效益&#xff1a; o 大模型的參數量非常大&#xff0c;訓練成本非常高&#xff0c;每家公司都去從頭訓練一個自己的大模型&#xff0c;這個事情的性價比非常低。 2.Prompt Engineering 的局限性&#xff1a; o Prompt Engineering 是一種相…

視圖庫對接系列(GA-T 1400)十二、視圖庫對接系列(本級)人員數據推送

背景 人體和非機動車和機動車類似的,只是請求的參數不一樣而已。人員數據推送 接入人員數據推送相對比較簡單,我們只需要實現對應的接口就ok了。 具體如圖: 有增刪改查接口,目前的話 因為我們是做平臺,我們只需要實現添加接口就可以了。 接口實現 service 層 /**** …

軟件工程面向對象 超市管理系統 需求分析 系統設計 課程設計報告

1、引言 系統簡述 超市管理系統的功能主要有前臺管理和后臺管理兩個大塊。其使用對象 有超市管理人員和超市銷售人員兩類。超市管理系統主要為了實現商品輸 入、 輸出管理數據的自動化&#xff0c; 提高商品統計信息的實時性&#xff0c; 減輕人工勞動強 度從而節省人力成本。實…

Perl 語言開發(九):深入探索Perl語言的文件處理

目錄 1. 文件打開與關閉 1.1 打開文件 1.2 關閉文件 2. 讀取文件內容 2.1 逐行讀取 2.2 一次性讀取整個文件 3. 寫入文件內容 3.1 覆蓋寫入 3.2 追加寫入 4. 文件測試操作 4.1 文件測試運算符 5. 文件路徑操作 5.1 文件路徑處理模塊 5.2 獲取文件路徑信息 6. 文…

探索加油小程序開發:便捷出行的科技新篇章

在快節奏的現代生活中&#xff0c;出行已成為人們日常生活中不可或缺的一部分。隨著移動互聯網技術的飛速發展&#xff0c;各類小程序以其輕量、便捷的特點迅速融入人們的日常生活&#xff0c;其中&#xff0c;加油小程序作為智慧出行領域的一股清流&#xff0c;正悄然改變著我…

《簡歷寶典》04 - 簡歷的“個人信息”模塊,要寫性別嗎?要放照片嗎?

平時幫助小伙伴們優化簡歷的時候&#xff0c;我看見他們有人會寫性別&#xff0c;有人不會寫。 目錄 1 招聘團隊的考慮 2 性別是無法改變的&#xff0c;能不寫就不寫 3 什么情況下&#xff0c;需要寫性別呢&#xff1f; 4 簡歷中要加照片嗎&#xff1f; 1 招聘團隊的考慮 …

Go語言---異常處理error、panic、recover

異常處理 Go 語言引入了一個關于錯誤處理的標準模式,即 error 接口,它是 Go 語言內建的接口類型,該接口的定義如下: package errorsfunc New(text string) error {return &errorString{text} }// errorString is a trivial implementation of error. type errorString st…

springboot事故車輛與違章車輛跟蹤系統-計算機畢業設計源碼03863

springboot事故車輛與違章車輛跟蹤系統 摘 要 科技進步的飛速發展引起人們日常生活的巨大變化&#xff0c;電子信息技術的飛速發展使得電子信息技術的各個領域的應用水平得到普及和應用。信息時代的到來已成為不可阻擋的時尚潮流&#xff0c;人類發展的歷史正進入一個新時代。…

W外鏈怎么樣,他們家的短網址免費的嗎?

W外鏈作為短網址服務的一種&#xff0c;體現了短網址技術的現代發展趨勢&#xff0c;它不僅提供了基礎的網址縮短功能&#xff0c;還擴展了一系列高級特性和增值服務&#xff0c;以適應更廣泛的市場需求。根據相關參考內容&#xff0c;W外鏈具有以下特點和優勢&#xff1a; 短域…

2024程序員行業風口和面試寶典

國際研究機構Gartner會在每年10月份左右發布下一年度的戰略發展趨勢預測&#xff0c;并在次年3月左右發布和網絡安全相關的趨勢預測。綠盟科技通過將近3年的趨勢預測進行分組對比分析后發現&#xff0c;除了眾人皆知的AI技術應用外&#xff0c;數據模塊化、身份優先安全、行業云…

軟考高級第四版備考--第13天(控制質量)Perform Quanlity Control

定義&#xff1a;為了評估績效&#xff0c;確保項目輸出完整、正確且滿足客戶期望而監督和記錄質量管理活動執行結果的過程。 作用&#xff1a; 核實項目可交付成果和工作已經達到主要干系人的質量要求&#xff0c;可供最終驗收&#xff1b;確定項目輸出是否達到預期的目的&a…

01-圖像基礎-顏色空間

1.RGB顏色空間 RGB是一種常用的顏色空間&#xff0c;比如一幅720P的圖像&#xff0c;所對應的像素點個數是1280*720&#xff0c;每一個像素點由三個分量構成&#xff0c;分別是R,G,B。 R代表紅色分量&#xff0c;G代表綠色分量&#xff0c;B代表藍色分量&#xff0c;以24位色來…

加密與安全_密鑰體系的三個核心目標之不可否認性解決方案

文章目錄 Pre概述不可否認性數字簽名&#xff08;Digital Signature&#xff09;證書是什么證書使用流程 PKICA證書層級多級證書證書鏈是如何完成認證的&#xff1f; 其他疑問1. Alice能直接獲取Bob的公鑰&#xff0c;是否還需要證書&#xff1f;2. 為什么即使能直接獲取公鑰也…

理解機器學習中的潛在空間(Understanding Latent Space in Machine Learning)

1、什么是潛在空間&#xff1f; If I have to describe latent space in one sentence, it simply means a representation of compressed data. 如果我必須用一句話來描述潛在空間&#xff0c;它只是意味著壓縮數據的表示。 想象一個像上面所示的手寫數字&#xff08;0-9&…

vue學習day01-vue的概念、創建Vue實例、插值表達式、響應式、安裝Vue開發者工具

1、vue的概念 Vue是一個用于構建用戶界面的漸進式 框架 &#xff08;1&#xff09;構建用戶界面&#xff1a;基于數據動態渲染頁面 &#xff08;2&#xff09;漸進式&#xff1a;循序漸進的學習 &#xff08;3&#xff09;框架&#xff1a;一條完整的項目解決方案&#xff…

GenAl如何改變 DevOps 中的軟件測試?

TestComplete 是一款自動化UI測試工具&#xff0c;這款工具目前在全球范圍內被廣泛應用于進行桌面、移動和Web應用的自動化測試。 TestComplete 集成了一種精心設計的自動化引擎&#xff0c;可以自動記錄和回放用戶的操作&#xff0c;方便用戶進行UI&#xff08;用戶界面&…

RTK_ROS_導航(2):衛星圖查看

目錄 1. 基于MapViz的衛星圖查看 1. 基于MapViz的衛星圖查看 安裝 # 源碼安裝 mkdir -p RTK_VISION/src cd RTK_VISION/src git clone https://github.com/swri-robotics/mapviz.git --branchmelodic-eol sudo apt-get install ros-$ROS_DISTRO-mapviz ros-$ROS_DISTRO-mapviz-…

IP-GUARD如何禁止電腦自帶攝像頭

IP-GUARD可以通過設備管理模塊禁止USB接口&#xff0c;所以USB外置攝像頭很容易就可以禁止了。 但是筆記本自帶攝像頭無法禁止&#xff0c;配置客戶端策略如下&#xff1a; device_control_unknown_mode1 device_control_unphysical_mode3

純電車的OBD接口

盡管傳統汽車的OBD接口主要用于監控和報告排放數據&#xff0c;但純電動車輛作為零排放的交通工具&#xff0c;其設計初衷與需求截然不同。因此&#xff0c;從法律條文和車管所的規定來看&#xff0c;純電動車輛是否仍需配置OBD接口這一問題&#xff0c;確實值得探討。理論上&a…