<!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>