最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue2路由跳轉(zhuǎn)傳參中文問題處理方案

 更新時(shí)間:2024年05月09日 16:19:12   作者:小袁搬碼  
在el-table中的記錄列表中放置了一個(gè) 操作按鈕,點(diǎn)這個(gè)按鈕時(shí)可以新增一個(gè)tab頁簽,并將通過路由傳參方式將一些信息傳遞到新打開的tab頁簽中,但發(fā)現(xiàn)傳遞中文參數(shù)時(shí)會(huì)出現(xiàn)報(bào)錯(cuò),所以本文給大家介紹了Vue2路由跳轉(zhuǎn)傳參中文問題處理方案,需要的朋友可以參考下

1. 問題描述

在el-table中的記錄列表中放置了一個(gè) 操作按鈕,點(diǎn)這個(gè)按鈕時(shí)可以新增一個(gè)tab頁簽,并將通過路由傳參方式將一些信息傳遞到新打開的tab頁簽中,但發(fā)現(xiàn)傳遞中文參數(shù)時(shí)會(huì)出現(xiàn) Failed to execute 'setRequestHeader' on 'XMLHttpRequest': String contains non ISO-8859-1 code point.的錯(cuò)誤,如下

1.1. 當(dāng)前vue組件

<template>
  <div class="app-container">
    <el-table :data="tableData.records" :key="tableKey" @cell-click="cellClick" size="small"
              @filter-change="filterChange" @selection-change="onSelectChange" @sort-change="sortChange"
              border fit row-key="id" ref="table" style="width: 100%;" v-loading="loading">
      <el-table-column align="center" type="selection" width="40px" column-key="selectionId"
                       :reserve-selection="true"/>
      <el-table-column label="模塊名" :show-overflow-tooltip="true"
                       align="center" prop="moduleName"
                       width="">
        <template slot-scope="scope">
          <span>{{ scope.row.moduleName }}</span>
        </template>
      </el-table-column>
      <!-- ...... -->
      <el-table-column
        label="操作" align="center" column-key="operation"
        class-name="small-padding fixed-width"
        width="180px">
        <template slot-scope="{ row }">
          <i
            @click="handleSetting(row)"
            class="el-icon-setting table-operation"
            style="color: #E6A23C"
            title="設(shè)置"
          />
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>

export default {
  name: "ConfigIndex",
  data() {
    return {
      loading: false
    };
  },
 
  methods: {
    /** 設(shè)置按鈕操作 */
    handleSetting(row) {
      console.log(row)
      const configId = row.id;
      const moduleName = row.moduleName; //有中文內(nèi)容,如 "第一個(gè)模塊"
      const params = { pageNum: 2,moduleName};
      //打開新的tab頁面  
      this.$tab.openPage("[" + moduleName + "]模塊配置", '/dev/settingsIndex/index/' + configId+"/"+moduleName, params);
    },
  }
};
</script>
<style lang="scss" scoped></style>

1.2. 跳轉(zhuǎn)到的vue組件

<template>
    <div>
        <!-- ...... -->
    </div>
</template>

<script>
import BasicInfoForm from "@/views/config/BasicInfoForm.vue";
import ConfigApi from "@/api/genConfig.js";

export default {
  name: "SettingsIndex",
  components: {
   BasicInfoForm
  },
  data() {
    return {
      activeName: "basic",
      info: {
        generateType: "0"
      },
      dbConfig: {}
    };
  },
  created() {
    //獲取路由中傳遞的參數(shù)
    const routeParams = this.$route.params
    if (routeParams) {
      this.info.id = routeParams.configId
      this.info.vueModuleName = routeParams.moduleName
    }
  }
  };
</script>

1.3. 出現(xiàn)的錯(cuò)誤

信息提示

在這里插入圖片描述

瀏覽器控制臺(tái)打印

xhr.js:126  Uncaught (in promise) TypeError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': String contains non ISO-8859-1 code point.
    at setRequestHeader (xhr.js:126:1)
    at Object.forEach (utils.js:238:1)
    at dispatchXhrRequest (xhr.js:120:1)
    at new Promise (<anonymous>)
    at xhrAdapter (xhr.js:12:1)
    at dispatchRequest (dispatchRequest.js:52:1)

2. 解決方法

原因是在前端跳轉(zhuǎn)頁面時(shí),url參數(shù)中的內(nèi)容出現(xiàn)了中文。要解決此問題必須對(duì)傳遞中文字符的參數(shù)值進(jìn)行編碼,在接收到參數(shù)后再對(duì)其進(jìn)行解碼即可解決。

JS中通過下面兩個(gè)方法進(jìn)行編碼與解碼操作

  • 編碼:encodeURIComponent(str)
  • 解碼:decodeURIComponent(str)

2.1. 當(dāng)前vue組件

<template>
  <div class="app-container">
    <el-table :data="tableData.records" :key="tableKey" @cell-click="cellClick" size="small"
              @filter-change="filterChange" @selection-change="onSelectChange" @sort-change="sortChange"
              border fit row-key="id" ref="table" style="width: 100%;" v-loading="loading">
      <el-table-column align="center" type="selection" width="40px" column-key="selectionId"
                       :reserve-selection="true"/>
      <el-table-column label="模塊名" :show-overflow-tooltip="true"
                       align="center" prop="moduleName"
                       width="">
        <template slot-scope="scope">
          <span>{{ scope.row.moduleName }}</span>
        </template>
      </el-table-column>
      <!-- ...... -->
      <el-table-column
        label="操作" align="center" column-key="operation"
        class-name="small-padding fixed-width"
        width="180px">
        <template slot-scope="{ row }">
          <i
            @click="handleSetting(row)"
            class="el-icon-setting table-operation"
            style="color: #E6A23C"
            title="設(shè)置"
          />
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>

export default {
  name: "ConfigIndex",
  data() {
    return {
      loading: false
    };
  },
 
  methods: {
    /** 設(shè)置按鈕操作 */
    handleSetting(row) {
      console.log(row)
      const configId = row.id;
      const moduleName = row.moduleName; //有中文內(nèi)容,如 "第一個(gè)模塊"
      const params = { pageNum: 2,moduleName};
      //打開新的tab頁面,并對(duì)URL中的  moduleName 通過 encodeURIComponent(moduleName)進(jìn)行編碼,解決中文問題
       this.$tab.openPage("[" + moduleName + "]模塊生成配置", '/tool/genSettingsIndex/index/' +configId+"/"+ encodeURIComponent(moduleName), params);
    },
  }
};
</script>
<style lang="scss" scoped></style>

2.2. 跳轉(zhuǎn)到的vue組件

<template>
    <div>
        <!-- ...... -->
    </div>
</template>

<script>
import BasicInfoForm from "@/views/config/BasicInfoForm.vue";
import ConfigApi from "@/api/genConfig.js";

export default {
  name: "SettingsIndex",
  components: {
   BasicInfoForm
  },
  data() {
    return {
      activeName: "basic",
      info: {
        generateType: "0"
      },
      dbConfig: {}
    };
  },
  created() {
    console.log("created====")
    //獲取路由中傳遞的參數(shù)
    const routeParams = this.$route.params
    if (routeParams) {
      this.info.id = routeParams.configId
      //這里通過  decodeURIComponent(routeParams.moduleName) 對(duì)路由中的moduleName參數(shù)值進(jìn)行解碼,解決中文問題
      this.info.vueModuleName = decodeURIComponent(routeParams.moduleName)
    }
  }
  };
</script>

以上就是Vue2路由跳轉(zhuǎn)傳參中文問題處理方案的詳細(xì)內(nèi)容,更多關(guān)于Vue2路由跳轉(zhuǎn)傳參的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • vue對(duì)storejs獲取的數(shù)據(jù)進(jìn)行處理時(shí)遇到的幾種問題小結(jié)

    vue對(duì)storejs獲取的數(shù)據(jù)進(jìn)行處理時(shí)遇到的幾種問題小結(jié)

    這篇文章主要介紹了vue對(duì)storejs獲取的數(shù)據(jù)進(jìn)行處理時(shí)遇到的幾種問題小結(jié),需要的朋友可以參考下
    2018-03-03
  • Vue PostCSS的使用介紹

    Vue PostCSS的使用介紹

    postcss一種對(duì)css編譯的工具,類似babel對(duì)js的處理,postcss只是一個(gè)工具,本身不會(huì)對(duì)css一頓操作,它通過插件實(shí)現(xiàn)功能,autoprefixer就是其一
    2023-02-02
  • js/vue如何實(shí)現(xiàn)函數(shù)(方法)當(dāng)做參數(shù)傳遞

    js/vue如何實(shí)現(xiàn)函數(shù)(方法)當(dāng)做參數(shù)傳遞

    這篇文章主要介紹了js/vue實(shí)現(xiàn)函數(shù)(方法)當(dāng)做參數(shù)傳遞方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2026-03-03
  • vue 子組件修改data或調(diào)用操作

    vue 子組件修改data或調(diào)用操作

    這篇文章主要介紹了vue 子組件修改data或調(diào)用操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • 解析Vue.use()是干什么的

    解析Vue.use()是干什么的

    今天通過本文給大家分享Vue.use是什么,主要包括vueEsign?插件的install是什么,element-ui的install是什么,為什么有的庫就不需要使用Vue.use,對(duì)vue.use()相關(guān)知識(shí)感興趣的朋友一起看看吧
    2022-06-06
  • 關(guān)于eslint和prettier格式化沖突問題

    關(guān)于eslint和prettier格式化沖突問題

    這篇文章主要介紹了eslint和prettier格式化沖突問題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-08-08
  • iview同時(shí)驗(yàn)證多個(gè)表單問題總結(jié)

    iview同時(shí)驗(yàn)證多個(gè)表單問題總結(jié)

    這篇文章主要介紹了iview同時(shí)驗(yàn)證多個(gè)表單問題總結(jié),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-09-09
  • Vue 打包體積優(yōu)化方案小結(jié)

    Vue 打包體積優(yōu)化方案小結(jié)

    這篇文章主要介紹了Vue 打包體積優(yōu)化方案小結(jié),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • Vue?(Vuex)中?store?基本用法

    Vue?(Vuex)中?store?基本用法

    Vuex?是一個(gè)專為?Vue.js?應(yīng)用程序開發(fā)的狀態(tài)管理模式。它采用集中式存儲(chǔ)管理應(yīng)用的所有組件的狀態(tài),并以相應(yīng)的規(guī)則保證狀態(tài)以一種可預(yù)測(cè)的方式發(fā)生變化,這篇文章主要介紹了Vue?中?store?基本用法,需要的朋友可以參考下
    2023-01-01
  • vue中渲染對(duì)象中屬性時(shí)顯示未定義的解決

    vue中渲染對(duì)象中屬性時(shí)顯示未定義的解決

    這篇文章主要介紹了vue中渲染對(duì)象中屬性時(shí)顯示未定義的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07

最新評(píng)論

班玛县| 五家渠市| 汨罗市| 贵德县| 随州市| 宜黄县| 绍兴县| 蕲春县| 阿合奇县| 肥乡县| 德惠市| 清远市| 都江堰市| 洛宁县| 金溪县| 开远市| 大安市| 雷波县| 奈曼旗| 武隆县| 新蔡县| 于田县| 申扎县| 三台县| 达孜县| 龙游县| 贵阳市| 盘锦市| 玉溪市| 紫云| 娱乐| 台州市| 宣城市| 拉萨市| 南部县| 扎赉特旗| 西畴县| 阿拉善右旗| 大洼县| 彰化市| 汾西县|