js confirm换行
时间: 2024-05-15 09:10:48 浏览: 11
JavaScript中的confirm()函数是一个弹出对话框,用于向用户询问是否确认执行某个操作。在确认框中,只能通过“确定”或“取消”按钮来响应用户的选择。如果你想在确认框中添加换行符,可以在文本中使用"\n"来实现。例如,以下代码可以创建一个带有换行符的确认框:
```
confirm("确定要删除该文件吗?\n该操作不可撤销!");
```
这将创建一个确认框,其中文本将显示为两行,第一行为“确定要删除该文件吗?”,第二行为“该操作不可撤销!”用户可以点击“确定”或“取消”来响应该对话框。
相关问题
this.$confirm换行
在使用this.$confirm进行换行时,可以使用$createElement来创建多个p标签,并将它们包裹在一个div标签中。例如,可以使用以下代码进行换行:
```
const h = this.$createElement;
this.$confirm('提示', {
title: '提示',
message: h('div', [
h('p', '是否将该账号密码重置为初始密码?'),
h('p', '成功后将密码设为默认密码,默认密码为用户账号')
]),
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
resetPasswords(params).then((res) => {
if (res.code == 200) {
this.$message.success('重置密码成功');
}
});
})
.catch(() => {
this.$message({
type: 'info',
message: '已取消重置密码',
});
});
```
这样可以在确认框中显示多行文本。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [vue this.$confirm中提示的文字换行](https://blog.csdn.net/weixin_45799001/article/details/125086460)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [confirm提示多行内容时换行问题](https://blog.csdn.net/qq_43432057/article/details/116981331)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [js使用小技巧](https://download.csdn.net/download/qq_17486363/7619983)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
vue this.$confirm显示后端返回数组按\n换行处理
你可以尝试在调用 `this.$confirm` 方法时,传入一个自定义的 `options` 对象,其中的 `message` 属性值可以使用字符串模板语法来进行换行处理。例如:
``` javascript
const message = response.data.join('\n');
this.$confirm({
title: '确认提示',
message: `后端返回的数组内容为:\n${message}`,
// 其他选项...
}).then(() => {
// 用户点击了确认按钮后的逻辑...
}).catch(() => {
// 用户点击了取消按钮后的逻辑...
});
```
在上面的代码中,我们将后端返回的数组内容转换成了以 `\n` 为分隔符的字符串,并使用字符串模板语法将其插入到了 `message` 属性值中,从而实现了换行处理。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)