欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue.js使用this.$confirm換行顯示提示信息實(shí)例

 更新時(shí)間:2024年10月17日 10:05:41   作者:EruruI  
在編寫(xiě)Web應(yīng)用時(shí),實(shí)現(xiàn)多行文本顯示通常需要用到HTML標(biāo)簽或JavaScript特定函數(shù),本文介紹了如何使用JavaScript的$createElement函數(shù)來(lái)創(chuàng)建多行文本顯示,$createElement可以創(chuàng)建任何HTML標(biāo)簽,使得在JavaScript中控制HTML輸出更加靈活,通過(guò)簡(jiǎn)單的代碼示例

Vue.js使用this.$confirm換行顯示提示信息

在寫(xiě)一個(gè)簡(jiǎn)單的按鈕點(diǎn)擊確認(rèn)框信息的時(shí)候,發(fā)現(xiàn)換行不能用\n。用了< br>發(fā)現(xiàn)也是字符串的輸出形式

去查了下發(fā)現(xiàn)需要使用$createElement來(lái)創(chuàng)建

這里我需要顯示兩行信息。

代碼如下:

creatNew(){
 const h = this.$createElement
        this.$confirm('提示', {
          title: '提示',
          message: h('div', [
            h('p', '新建會(huì)導(dǎo)致之前設(shè)置失效'),
            h('p', '是否繼續(xù)新建?')
          ]),
          confirmButtonText: '確定',
          cancelButtonText: '取消'
        }).then(() => {
        ....//調(diào)用新建方法
        }).catch(()=>({}))//不要忘記catch
        //最后可以.finally(()=>({}))
        }

解釋

  • h('div')就表示創(chuàng)建一個(gè)div標(biāo)簽,
  • 如果寫(xiě)成h('div',{class:'...'})就可以定義class,如:
 h('i', { class: 'el-icon-question' })
  • 如果寫(xiě)成下面的,則可以定義props。(以element的彈出框el-tooltip為例)
h('el-tooltip',{props:{
					content: (function() {
                  	return '彈出信息'
                  	})(),
                	placement: 'top'
                	}})
  • 包含關(guān)系用h('div',[...]),如div中包含兩個(gè)p標(biāo)簽:(可以繼續(xù)嵌套)
h('div', [
            h('p', '第一個(gè)p'),
            h('p', '第二個(gè)p')
          ])

Vue的this.$confirm中注意this的指向

Vue開(kāi)發(fā)過(guò)程中遇到this. confirm( )里面的this失效問(wèn)題,就是當(dāng)你想在里面使用data數(shù)據(jù)的時(shí)候,我們往往是 this.dataName這種方式拿到值,但在 this.confirm()里面的this失效問(wèn)題,就是當(dāng)你想在里面使用data數(shù)據(jù)的時(shí)候,我們往往是this.dataName這種方式拿到值,但在this. confirm()里面的this失效問(wèn)題,就是當(dāng)你想在里面使用data數(shù)據(jù)的時(shí)候,我們往往是this.dataName這種方式拿到值,但在this.confirm()里面的this不是指向當(dāng)前vue了,所以是取不到data的數(shù)據(jù)。

解決方法

因此我們?cè)谑褂胻his.$confirm()前先保存this

let _this = this
			const _this = this
            this.$confirm({
              title: '當(dāng)前郵件正文內(nèi)容爲(wèi)空',
              content: h => <div style="color:red;">確認(rèn)是否發(fā)佈?</div>,
              onOk () {
                console.log('保存提交的對(duì)象', this.objData)
                _this.loading = true
                initAxios.saveMail(_this.objData).then((res) => {
                  _this.loading = false
                  if (res.data.code === '200' && res.data.result) {
                    _this.$router.go(-1) // 處理返回需要點(diǎn)兩次的問(wèn)題
                    _this.$message.success('發(fā)佈成功!')
                  }
                })
              },
              onCancel () {
                return false
              }
            })

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論