filter 过滤器的基本使用

<!DOCTYPE html>
<html lang="zh">

	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<title>filter过滤器基本使用</title>
	</head>
	<body>
		<div id="app">
			<span ref='spmsg'>{{ msg.name | slite }}</span>
		</div>
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
		<script>
			var vm = new Vue({
				el: '#app',
				data: {
					msg: {name:'这是一段文字'}
				},
				methods: {
				},
				filters: {
					slite(val) {
						if(val.length >= 3) {
							var value = val.substring(0, 3) + "..."
							return value
						}
						return val
					}
				}
			})
		</script>
	</body>

</html>

posted on 2019-04-29 09:42  A-pupli  阅读(108)  评论(0编辑  收藏  举报