これを間違ってインポートする必要があると思われますが、わかりません。私はgithubの指示に従った。それは私がnpm install
それをすることができ、次にちょうどimport swal from 'sweetalert2'
ことができると言います。 js
とcss
ファイルも使用する必要がありますか?アラートがスローされたときにスウィートアラート2がモーダルとして表示されない
私の窓の左下には逃げない奇妙な警告が表示されます。あなたはCSSファイル含める必要があり
import React, { Component } from 'react';
import swal from 'sweetalert2';
class TestSwal extends Component {
componentDidMount() {
swal({
title: 'Are you sure?',
text: 'You will not be able to recover this imaginary file!',
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, keep it'
}).then(
function() {
swal('Deleted!', 'Your imaginary file has been deleted.', 'success');
},
function(dismiss) {
// dismiss can be 'overlay', 'cancel', 'close', 'esc', 'timer'
if (dismiss === 'cancel') {
swal('Cancelled', 'Your imaginary file is safe :)', 'error');
}
}
);
}
render() {
return <div>Test Swal</div>;
}
}
export default TestSwal;
ここに新しいリリースの使用例があります:https://github.com/limonte/sweetalert2-webpack-demo#indexjs –