这段在vue官网能成功运行的代码,在codepen里也没能运行,说vue没被定义Uncaught ReferenceError: Vue is not defined

news/2024/7/9 23:56:32 标签: vue, codepen

html

<div id="event-handling">
  <p>{{ message }}</p>
  <button v-on:click="reverseMessage">反转 Message</button>
</div>

css

.demo {
  font-family: sans-serif;
  border: 1px solid #eee;
  border-radius: 2px;
  padding: 20px 30px;
  margin-top: 1em;
  margin-bottom: 40px;
  user-select: none;
  overflow-x: auto;
}

js

const EventHandlingApp = {
  data() {
    return {
      message: 'Hello Vue.js!'
    }
  },
  methods: {
    reverseMessage() {
      this.message = this.message
        .split('')
        .reverse()
        .join('')
    }
  }
}

Vue.createApp(EventHandlingApp).mount('#event-handling')

是怎么回事呢,codepen不能用吧
就算codepen能用,又怎么搬到vscode里,或者说浏览器里能显示呢?

2022年4月6日
修改
这样可以。

<!DOCTYPE html>
<html>
	<body>
		<div id="event-handling">
			<p>{{ message }}</p>
			<button @click="reverseMessage">反转 Message</button>
		  </div>
		  
		<script src="https://unpkg.com/vue@next"></script>
		<script>
			const EventHandlingApp = {
				data() {
					return {
						message: 'Hello Vue.js!'
					}
				},
				methods: {
					reverseMessage() {
						this.message = this.message.split('').reverse().join('')
					}
				}
			}
			
			Vue.createApp(EventHandlingApp).mount('#event-handling')
		</script>
		<style>
			.demo {
font-family: sans-serif;
border: 1px solid #eee;
border-radius: 2px;
padding: 20px 30px;
margin-top: 1em;
margin-bottom: 40px;
user-select: none;
overflow-x: auto;
}

			
			</style>
	</body>
</html>

记住,不需要这段代码

const app = Vue.createdApp({});

大概是因为有了

const EventHandlingApp = {}
Vue.createApp(EventHandlingApp)

http://www.niftyadmin.cn/n/957963.html

相关文章

根据数组给小程序checkbox-group 赋值显示勾选

var tt res.data[0].fuli.split(",");//你数据库保存的数据var s3 [];var array1 ["年终奖","双休","五险","加班补贴","包食宿","有年假","技术培训","提成"] //checkbox 所有…

小程序修改数组参数

//修改数组edit:function (e){//这个参数“e”的具体作用&#xff0c;请参考微信小程序官方提供的说明&#xff0c;地址为https://mp.weixin.qq.com/debug/wxadoc/dev/framework/view/wxml/event.html?t20161107var dataset e.target.dataset; var Index dataset.index; //在…

似乎是好了哎,运行出了Counter: 0,而不是刚才一直的那样,再试一个试试

Counter: 0 试了一下&#xff0c;不行&#xff0c;怎么又变成这个了呢&#xff1f;&#xff1f; 运行出来的 Counter: {{ counter }} 这个运行&#xff0c;不行&#xff0c;不知道为啥 <!DOCTYPE html> <html lang"en"><head><meta charset&…

tp5查询数据转为数组遍历

$touser Db::table()->alias(a)->join(b, a.email b.username)->join(c, c.userid b.userid)->field(c.)->select()->toArray();//加->toArray();//遍历发送微信消息$num count($touser);//获取数组长度//遍历for ($x 0; $x < $num; $x) {}

解决mybatis嵌套查询使用PageHelper分页不准确

springboot项目中嵌套查询使用PageHelper发现使用结果不正确&#xff0c;上PageHelper官网看了一下果然是有坑。。 就是下面这种映射会导致分页结果不正确&#xff0c;既然下面这种不行换了一种方式 <?xml version"1.0" encoding"UTF-8"?> <!…

JDK内置工具使用(jps、jstack、jmap、jstat)

一、JPS 1、jps -lvm&#xff1a;用于查看当前机器上已装载的jvm 二、jstack 1.1&#xff1a;查看进程的线程数&#xff0c;找出进程内最耗费CPU的线程&#xff1a; top -Hp 19931 。 可以看到耗费CPU的线程的pid是20097 1.2&#xff1a; printf "%x\n" 20097 得…

tp5小程序支付

wx.request({url: , //请求接口的urlmethod: GET, //请求方式data:{openid:openid,//获取用户openidfee:qian, //商品价格},header: {content-type: application/json // 默认值},success: function (res) {console.log(res.data);console.log(调起支付);wx.requestPayment({ti…

maven设置每次构建获取最新版本号

<dependency><groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>[2.40.0,)</version> </dependency> 以上注意version里的[2.40.0,)表示取2.40.0以上最新版本