我在运行 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)
谁能帮我?
当我想将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)
怎么处理?我的代码有问题吗?