gpt4 book ai didi

javascript - 如何将 'svg'格式的图标添加到SweetAlert for Bootstrap?

转载 作者:行者123 更新时间:2023-11-29 20:33:16 27 4
gpt4 key购买 nike

我尝试在警报“swal”中将 image.svg 图标添加到 imageUrl。它与文件“index.js”位于同一文件夹中。图标未添加

代码在这里:https://stackblitz.com/edit/react-y5v8tc?file=index.js

import React, { Component } from 'react';
import { render } from 'react-dom';
import Hello from './Hello';
import './style.css';
import swal from 'sweetalert';

class App extends Component {
constructor() {
super();
this.state = {
name: 'React'
};
}

show = () => {
console.log('show')
}

componentDidMount() {
swal({
title: 'dddddd',
text: 'dddddddd',
icon: "info",
buttons: true,
showCancelButton: false,
imageUrl: './image.svg',
buttons: {
confirm : {text: 'button'}
},
confirmButtonClass: "btn-info",
closeOnConfirm: false
})
.then((isConfirm) => {
if (isConfirm) {
this.show();
}
});
}



render() {
return (
<div>
<Hello name={this.state.name} />
<p>
Start editing to see some magic happen :)
</p>
</div>
);
}
}

render(<App />, document.getElementById('root'));

最佳答案

首先尝试加载图标:

import Icon from './image.svg';

然后重用它从 sweet alert 中删除图标:

componentDidMount() {
...
icon: {Icon},
....
}

Link附上。

关于javascript - 如何将 'svg'格式的图标添加到SweetAlert for Bootstrap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57581568/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com