我自己的代码是:
<script setup>
import { ElButton } from 'element-plus';
import { ref } from 'vue';
import SvgIcon from '../utils/SvgIcon.vue';
const isPause = ref(false);
// 根据网上 vite-plugin-svg-icons 教程写的
const playIcon = () => <SvgIcon name="play"/>
</script>
<template>
<el-button v-if="isPause" type="primary" size="small">Pause</el-button>
/ / 这里 icon="playIcon"
<el-button v-else type="primary" icon="playIcon" size="small"></el-button>
</template>
<style scoped lang="scss"></style>
报错:
查了一下,似乎这是 JSX 语法,Vue 不支持,虽然还看到可以用 Babel 但是我不知道 “正规写法”应该长啥样?
难道是嵌套?我用 React 的经验,组件有许多内部布局,比如右对齐,间隔等。嵌套法真的不是一个传入图标的好方法。
我看 el-button 文档写 icon prop 接受 string / Component 。
如何传进去?