[Vue warn]: Cannot find element: #app

博主在开发中一直以为引入的vue.js有问题,换了很多版本并配置npm,后来发现是手写的vue.js引入顺序有误,应在最后引入,因为要先有id为vue - app的div,vue才能获取相应元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述代码很简单,如下所示

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var Vm = new Vue({
				el: '#app',
				data: {
					message: 'Hello Vue!'
				}
			})
		</script>
	</head>
	<body>
		<div id="app">
			{{message}}  
		</div>
	</body>
</html>

一直以为是引入的vue.js有问题换了好多,然后又配置npm

原来是手写的vue.js要在最后引入

因为要先有id为vue-app的div,vue才能获取相应的元素。

更改后:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="app">
			{{message}}  
		</div>
	</body>
	<script type="text/javascript">
			var Vm = new Vue({
				el: '#app',
				data: {
					message: 'Hello Vue!'
				}
			})
		</script>
</html>

在这里插入图片描述

<el-form-item label="所属站点”prop="substid"> <el-select filterable v-model="ruleform.substid"placeholder="请选择站点”@change="substidChange"> <el-option v-for="item in substidList" :key="item.substid" :label="item.substname" :value="item.substid"> </el-option> </el-select> </el-form-item>substidChange(){ let that = this; that.editdata = ""; let obj = {}; obj = that.substidList.find((item)=>{ return item.substid === that.ruleform.substid;//筛选出匹配数据 }); that.dataparam.substid = that.ruleform.substid; },切换站点时会报错[Vue warn]: Error in v-on handler: "TypeError: Cannot set properties of undefined (setting 'substid')" found in ---> <ElSelect> at packages/select/src/select.vue <ElFormItem> at packages/form/src/form-item.vue <ElForm> at packages/form/src/form.vue <AlarmEdit> at src/components/system/alarm/AlarmEdit.vue <ElDrawer> at packages/drawer/src/main.vue <AlarmView> at src/components/system/alarm/AlarmView.vue <Main> at src/components/main.vue <App> at src/App.vue <Root> warn @ vue.runtime.esm.js:619 logError @ vue.runtime.esm.js:1893 globalHandleError @ vue.runtime.esm.js:1888 handleError @ vue.runtime.esm.js:1848 invokeWithErrorHandling @ vue.runtime.esm.js:1871 invoker @ vue.runtime.esm.js:2188 invokeWithErrorHandling @ vue.runtime.esm.js:1863 Vue2.$emit @ vue.runtime.esm.js:3903 emitChange @ element-ui.common.js:8763 handleOptionSelect @ element-ui.common.js:8943 invokeWithErrorHandling @ vue.runtime.esm.js:1863 Vue2.$emit @ vue.runtime.esm.js:3903 dispatch @ emitter.js:29 selectOptionClick @ element-ui.common.js:8123 click @ element-ui.common.js:7977 invokeWithErrorHandling @ vue.runtime.esm.js:1863 invoker @ vue.runtime.esm.js:2188 original._wrapper @ vue.runtime.esm.js:6961 vue.runtime.esm.js:1897 TypeError: Cannot set properties of undefined (setting 'substid') at VueComponent.substidChange (AlarmEdit.vue:204:1) at invokeWithErrorHandling (vue.runtime.esm.js:1863:26) at VueComponent.invoker (vue.runtime.esm.js:2188:14) at invokeWithErrorHandling (vue.runtime.esm.js:1863:26) at VueComponent.Vue2.$emit (vue.runtime.esm.js:3903:9) at VueComponent.emitChange (element-ui.common.js:8763:14) at VueComponent.handleOptionSelect (element-ui.common.js:8943:14) at invokeWithErrorHandling (vue.runtime.esm.js:1863:26) at VueComponent.Vue2.$emit (vue.runtime.esm.js:3903:9) at VueComponent.dispatch (emitter.js:29:22)
最新发布
03-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值