Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

重写elementUI Transfer组件后,提示找不到

因为elementUI Transfer性能问题,参考重写了这个组件.但引入后,为什么找不到呢?

一般认为是路径错误,应试如何写?
路径部分如下:

import Transfer from '../common/transfer'  //引入自重写组件
  export default {
   components:{            
     Transfer:Transfer      // 定义重写组件
   },

操作步骤:
node_modules/element-ui/packages/transfer,文件夹复制,然后放入vue项目路径的 src/common

一.App.vue中使用如下:

<template>
  <Transfer
    filterable
    :filter-method="filterMethod"
    filter-placeholder="请输入城市拼音"
    v-model="value"
    :data="data">
  </Transfer>
</template>

<script>
import Transfer from '../common/transfer'  //引入自重写组件
  export default {
   components:{            
     Transfer:Transfer      // 定义重写组件
   },
    data() {
      const generateData = _ => {
        const data = [];
        const cities = ['上海', '北京';
        const pinyin = ['shanghai', 'beijing';
        cities.forEach((city, index) => {
          data.push({
            label: city,
            key: index,
            pinyin: pinyin[index]
          });
        });
        return data;
      };
      return {
        data: generateData(),
        value: [],
        filterMethod(query, item) {
          return item.pinyin.indexOf(query) > -1;
        }
      };
    }
  };
</script>

二.结构截图如下:

image

三.错误提示如下:

 ERROR  Failed to compile with 1 errors                                                                                                 2:41:54 PM

This relative module was not found:

* ../common/transfer in ./node_modules/cache-loader/dist/cjs.js??ref--13-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=script&lang=js&

image

四.浏览器console:
image


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

.vue

import Transfer from '../common/transfer.vue'

components:{
    Transfer,// 写一个就可以了;(两个也是可以用的)
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...