Vue实现禁止链接打开

Vue提供了一个特殊的变量$event,用于访问原生DOM事件。

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Vue实现禁止链接打开</title>
 </head>
 <body>
 	<div id="app">
	<a href="https://blog.csdn.net/BADAO_LIUMANG_QIZHI" @click="prohibitOpen('不要打开这个网址:https://blog.csdn.net/BADAO_LIUMANG_QIZHI',$event)">你打不开这个网址</a>
	</div>
<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>  
<script>
	new Vue({
		el:'#app',
		methods:{
			prohibitOpen:function(message,event){
				event.preventDefault();
				window.alert(message);
			}
		}
	})
</script>
 </body>
</html>

猜你喜欢

转载自blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/82749352
今日推荐