小编rub*_*grv的帖子

如何修复此错误 [Vue 警告]: Unknown custom element: <nuxt-link> in unit testing with Jest

我在运行 npm run 测试时遇到问题。错误是

 [Vue warn]: Unknown custom element: <nuxt-link> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
Run Code Online (Sandbox Code Playgroud)

SidebarCMS.spect.js

import { shallowMount } from "@vue/test-utils";
import SidebarCMS from "../layouts/SidebarCMS";

const factory = () => {
  return shallowMount(SidebarCMS, {});
};

describe("SidebarCMS", () => {

  test("renders properly", () => {
    const wrapper = factory();
    expect(wrapper.html()).toMatchSnapshot();
  });
});
Run Code Online (Sandbox Code Playgroud)

谁能帮我?

vue.js nuxt.js

5
推荐指数
1
解决办法
900
查看次数

如何修复未捕获(承诺中)类型错误:无法设置未定义的属性

当我想将API结果中的值发送到数据时出现错误,错误是这样的

Uncaught (in promise) TypeError: Cannot set property 'notification' of undefined at eval (HeaderPortal.vue?070f:367)
Run Code Online (Sandbox Code Playgroud)

这是我的HeaderPortal.vue

data() {
  return {
    notification: []
  }
}

mounted: {
  const res = this.GET('/api/v2/notification', 'BEARER', null).then(function(res) {
     console.log(JSON.parse(res))
     this.notification = JSON.parse(res);
  });
}
Run Code Online (Sandbox Code Playgroud)

this.GET 来自这里

methods: {
  async GET(url, headers, callback) {
    const options = headers === 'BASIC' ? HEADERS_BASIC : HEADERS_BEARER;
    try {
      const response = await axios.get(`${BASE_URL}${url}`, options);
      return (JSON.stringify(response));
    } catch (e) {
      console.error(e);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

怎么处理?我的代码有问题吗?

nuxt.js

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

nuxt.js ×2

vue.js ×1