uni-app:Uncaught TypeError: Cannot read property ‘createElement‘ of undefined移动端调试基座白屏报错问题

云打包后也是白屏!!! 

 这里打包后在手机上安装启动后一样白屏而且还看不到报错!!手机模拟器基座调试运行后可以看到报错,所以这里建议用手机模拟器基座调试!!!

手机模拟器基座调试:

手机打开开发人员选项后打开USB调试:

开发人员选项这里因为每个手机的型号不同打开方式也不同查一下自己手机型号的开发者选项如何打开就行

只需要打开USB调试就可以了其他的默认不用管

用手机USB链接电脑运行手机模拟器App基座:

刷新运行:

运行后报错:

exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->Uncaught TypeError: Cannot read property 'createElement' of undefined

createElement这里在文件搜索里找到引用的外部js文件:

 因为createElement只能在H5里使用app里不行!!!

只能加if判断

// #ifdef H5
     *****js代码块*****
// #endif

大概长这样:

但是这样的话js就用不了了 本菜鸡也很难受 各位大神就再另外想办法吧

这里说的是在移动端运行时

这里注意看官方文档:


https://uniapp.dcloud.net.cn/matter.htmlhttps://uniapp.dcloud.net.cn/matter.html

 大概就是长这样吧:


<template>

</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				
			}
		},
		onLoad() {
				
		},
		created() {

		},
		mounted() {

		},
		// 方法
		methods: {
				

		}
</script>

<script module="test" lang="renderjs">
	export default {
		mounted() {
			
		},
		methods: {
			
		}
	}
</script>

<style>
	@import"@/style/css/login/login.css";
</style>

也就是说页面上得有两个script一个是用renderjs标注一下

我的理解是带renderjs的script在移动端执行的这个过程应该是把代码编译成可以在手机上被认识的

大概页面的编译执行流程长这样:

 renderjs用法参考文章:

https://uniapp.dcloud.net.cn/tutorial/renderjs.htmlhttps://uniapp.dcloud.net.cn/tutorial/renderjs.html

https://juejin.cn/post/7049185827582115870https://juejin.cn/post/7049185827582115870

运行时白屏也不光是因为rendersjs的问题,语法规则错误也会导致报错白屏这里要细心别到时候花半天时间改完代码之后还是白屏出不来结果发现压根就不是这里的问题那就难受了

猜你喜欢

转载自blog.csdn.net/qq_45609680/article/details/129446548