当前位置:网站首页>Nuxt reports an error: render function or template not defined in component: anonymous
Nuxt reports an error: render function or template not defined in component: anonymous
2022-07-04 09:35:00 【Dandelion_ drq】
problem
stay dev hot reload Development under the mode of , It was good , This error occurred after adding a piece of code .
The detailed error information is as follows :
This prompt seems to be a system level error , No clue . therefore google And , I found many people who mentioned this mistake issue, However …… I didn't see a solution .
ok , It's better to look at it by yourself .
So cancel the Dafa ...
I'll comment out the added part of the code first , preservation , Sure enough, there is no more wrong report .
Take a look at the code added in this part ~
analysis & solve
browser.js
let browser = {
};
const ua = navigator.userAgent;
browser = {
weixin: ua.toLowerCase().indexOf('micromessenger') !== -1,
ios: (/\(i[^;]+;( U;)? CPU.+Mac OS X/).test(ua),
android: ua.indexOf('Android') > -1 || ua.indexOf('Adr') > -1
}
export default browser;
The above is what I added browser.js file , Then I was in a .vue In file import With it .
It's OK to look at this part of the code , So I read the wrong content carefully (PS: Take that. show all frames Check on )……
This time I found a key point —— yes server render Error of .
Um. ~~ It's easy to understand .Nuxt Of universal Patterns support isomorphism 【https://zh.nuxtjs.org/api/configuration-mode/#mode-%E5%B1%9E%E6%80%A7】.
PS: See this article for isomorphism ( Talk about the front end 「 isomorphism 」)
And for Nuxt Isomorphism of , Our project code is on the server (Node) And the client ( browser ) Will run , This is the benefit of isomorphism , We can write a set of code , Both ends can execute . But it is precisely because both sides will execute , We need to pay attention to the differences between the two environments . For example, the server is node Environmental Science , So it's not window Object's . And look at what I added browser.js File code , Yes navigator.userAgent, It's actually window Properties of . So I found the cause of the problem .
The way to modify it is very simple , We can judge what the current environment is , The server does not execute , and Nuxt There are also offers process.client and process.server Two properties for us . So modify the code as follows :
let browser = {
};
if (process.client) {
const ua = navigator.userAgent;
browser = {
weixin: ua.toLowerCase().indexOf('micromessenger') !== -1,
ios: (/\(i[^;]+;( U;)? CPU.+Mac OS X/).test(ua),
android: ua.indexOf('Android') > -1 || ua.indexOf('Adr') > -1
}
}
export default browser;
Save refresh page , Sure enough, I didn't report any more mistakes ~~
【 The following is nonsense 】
Think about it , I still stay at the level of using these frameworks , Sometimes when I see some mistakes at the bottom, I have no clue , Blind google 了 . But in fact, sometimes carefully analyze the error prompt , You may find useful information ……
Like this error report , I'll search directly render function or template not defined in component: anonymous This error prompt found github issue There is no solution yet close the , Because this is not Nuxt Of bug, But because I don't know to consider the pit of homogeneous code , The rendering of the server fails . Therefore, we should analyze and think by ourselves before looking at problems , And for the framework used in my project , You still need to understand its principle , To know what it is, but also to know why !!
边栏推荐
- Reading notes on how to connect the network - hubs, routers and routers (III)
- HMS core helps baby bus show high-quality children's digital content to global developers
- 《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)
- el-table单选并隐藏全选框
- lolcat
- H5 audio tag custom style modification and adding playback control events
- China electronic grade sulfur trioxide Market Forecast and investment strategy report (2022 Edition)
- Function comparison between cs5261 and ag9310 demoboard test board | cost advantage of cs5261 replacing ange ag9310
- Write a jison parser from scratch (5/10): a brief introduction to the working principle of jison parser syntax
- Global and Chinese markets of thrombography hemostasis analyzer (TEG) 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

Daughter love: frequency spectrum analysis of a piece of music

Solve the problem of "Chinese garbled MySQL fields"

MySQL foundation 02 - installing MySQL in non docker version

2022-2028 global edible probiotic raw material industry research and trend analysis report

C # use gdi+ to add text to the picture and make the text adaptive to the rectangular area

PHP student achievement management system, the database uses mysql, including source code and database SQL files, with the login management function of students and teachers

C # use ffmpeg for audio transcoding

【LeetCode 42】501. Mode in binary search tree

Daughter love in lunch box
自动化的优点有哪些?
随机推荐
If you can quickly generate a dictionary from two lists
《网络是怎么样连接的》读书笔记 - WEB服务端请求和响应(四)
PMP registration process and precautions
Launpad | 基礎知識
After unplugging the network cable, does the original TCP connection still exist?
2022-2028 global small batch batch batch furnace industry research and trend analysis report
`Example of mask ` tool use
Rules for using init in golang
Global and Chinese markets of thrombography hemostasis analyzer (TEG) 2022-2028: Research Report on technology, participants, trends, market size and share
Explanation of closures in golang
Reading notes on how to connect the network - hubs, routers and routers (III)
SSM online examination system source code, database using mysql, online examination system, fully functional, randomly generated question bank, supporting a variety of question types, students, teache
Luogu deep foundation part 1 Introduction to language Chapter 4 loop structure programming (2022.02.14)
什么是权限?什么是角色?什么是用户?
Launpad | basic knowledge
Flutter 小技巧之 ListView 和 PageView 的各种花式嵌套
Daughter love in lunch box
Nurse level JDEC addition, deletion, modification and inspection exercise
Write a jison parser from scratch (2/10): learn the correct posture of the parser generator parser generator
2022-2028 global industry research and trend analysis report on anterior segment and fundus OTC detectors