Vue iconfont 编码转换
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue iconfont 编码转换</title>
<link rel="stylesheet" href="./iconfont/iconfont.css">
<style>
body {
margin: 0;
padding: 0;
}
#bar {
position: fixed;
bottom: 0;
width: 100vw;
height: 49px;
display: flex;
justify-content: space-between;
align-items: stretch;
}
.bar-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
}
.icon {
font-size: 24px;
}
.name {
font-size: 12px;
}
</style>
</head>
<body>
<div id="app">
<div id="bar">
<div class="bar-item" v-for="item in items">
<div class="icon iconfont">{{ iconfont(item.icon) }}</div>
<div class="name">{{ item.name }}</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
app = new Vue({
el: '#app',
data: {
items: [
{
name: '首页',
icon: '',
},
{
name: '分类',
icon: '',
},
{
name: '购物车',
icon: '',
},
{
name: '个人中心',
icon: '',
},
]
},
methods: {
iconfont: function (icon) {
const reg = /(&#x)?(.*)/
let iconfontName
if(reg.test(icon)) {
iconfontName = reg.exec(icon)[2]
}
return String.fromCharCode(parseInt(iconfontName, 16))
}
}
})
</script>
</body>
</html>