Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

vue.js - "export not found in.. " when trying to import class in router

In my router class, I would like to guard if the user search for an entity ID directly by typing in the address bar (rather than clicking through the UI) - "http://application/customer/123". So I need to run the ID against the API to check if the customer exist first, in the 'beforeEnter'.

My problem is: I'm getting the warning "export 'customerService' was not found in '../services/customerService. And I'm also getting the error Home.vue?76f2:17 Uncaught TypeError: _services_customerService__WEBPACK_IMPORTED_MODULE_2__.customerService is not a constructor when running the page.

Here is my code:

// Path: Project/src/services/customerService.js
export default class customerService {}

// Path: Project/src/router/index.js
import { customerService } from '../services/customerService.js';

const routes = [
  { 
    path: '/customer/:id?', 
    name:'customer', 
    component: Customer,
    beforeEnter: async (to, from, next) => {
      // This could be from trying to access the page by directly typing the URL in the address bar
      if (from.name !== "customers") {
        var m = new customerService();
        var resp = await m.getCustomerById(to.params.id);
      } else {
        next();
      }
    },
  },
]

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

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...