ElementUI中弹窗使用textarea原样显示SpringBoot后台带换行的StringBuilder内容

场景

前端进行导入Excel后,后台SpringBoot将导入结果进行反馈。

后台代码使用的是StringBuilder拼接一个带换行\n的回显内容。

 

然后在导入结束后前端怎样使用ElementUI的弹窗将反馈结果包括换行原样显示。

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

前端调用结果收到的msg信息为

 

    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<textarea readonly style = 'border:0;width:100%;height:100px;resize:none;outline: none;'>"+response.msg+"</textarea>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    }

注:

调用ElementUI的弹窗的代码

this.$alert()

然后要想原样输出带换行的内容,可以使用textarea标签,并且设置标签的一些属性即可。

将dangerouslyUseHTMLString属性设置为 true,message 就会被当作 HTML 片段处理。

然后设置readonly属性使其不可编辑。

然后添加一些样式,去掉边框,设置宽度和高度,去掉点击时的边框显示。

最终的回显效果

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
可以使用以下代码实现在Java Swing弹出窗口并在TextArea显示文件内容的功能: ```java import java.awt.BorderLayout; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; public class FileViewer extends JFrame implements ActionListener { private JButton openButton; private JTextArea textArea; public FileViewer() { super("File Viewer"); // Create components openButton = new JButton("Open"); openButton.addActionListener(this); textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); // Add components to content pane Container contentPane = getContentPane(); contentPane.add(openButton, BorderLayout.NORTH); contentPane.add(scrollPane, BorderLayout.CENTER); // Set window properties setSize(400, 300); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); } public static void main(String[] args) { // Create and show window FileViewer fileViewer = new FileViewer(); fileViewer.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == openButton) { // Create file chooser dialog JFileChooser fileChooser = new JFileChooser(); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { // Get selected file File file = fileChooser.getSelectedFile(); try { // Read file contents BufferedReader reader = new BufferedReader(new FileReader(file)); String line; StringBuilder sb = new StringBuilder(); while ((line = reader.readLine()) != null) { sb.append(line); sb.append(System.lineSeparator()); } reader.close(); // Set text area contents textArea.setText(sb.toString()); } catch (Exception ex) { ex.printStackTrace(); } } } } } ``` 这段代码会创建一个名为 "File Viewer" 的窗口,其包含一个 "Open" 按钮和一个文本区域。当用户点击 "Open" 按钮时,会弹出一个文件选择器对话框,用户可以选择要读取的文件。然后,程序会读取文件内容并将其显示在文本区域

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

霸道流氓气质

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值