console
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!',
fixStr: [],
str: '',
fixInx: '',
arrShow: ''
},
methods: {
clickTest () {
let a = this.str
let b = a.replace(/\s*/g,"")
let c = b.split(',')
let d = []
c.map((item) => {
let e = item
let start = 1
let end = e.indexOf(':') -1
let fixStrart = "{{$t('"+ this.fixInx +"."
let fixEnd = "')}}"
let fixJSA = "this.$t('"+ this.fixInx +"."
let fixJSB = "')"
let f = fixStrart + e.slice(start, end) + fixEnd
let g = fixJSA + e.slice(start, end) + fixJSB
let labelStr = `:label="$t('`+ this.fixInx +"."
let labelEnd = `')"`
let h = labelStr + e.slice(start, end) + labelEnd
let plaStr = `:placeholder="$t('`+ this.fixInx +"."
let plaEnd = `')"`
let i = plaStr + e.slice(start, end) + plaEnd
let j = ':label="`${$t(' + "'" + this.fixInx + "." + e.slice(start, end) + "')}:`" + '"'
let fixOBj = {
fixVue: f,
fixJs: g,
label: h,
labelPoint: j,
pla: i,
fixCH: e.slice(e.indexOf(':')+ 2)
}
d.push(fixOBj)
})
this.fixStr = d
this.arrShow = ""
},
clickArr () {
let a = this.str
let b = a.replace(/\[/g, "")
let c = b.replace(/",/g, '": ')
let d = c.replace(/\]/g, '')
let e = d.replace(/\,/g, ',\n')
this.arrShow = e
this.fixStr = []
},
copyClick (str) {
let cInput = document.createElement('input')
cInput.value = str
document.body.appendChild(cInput)
cInput.select()
document.execCommand('copy')
cInput.remove()
}
}
})
<div id="app">
处理数据<input v-model="str"></input>
<button @click="clickTest">替换</button>
<button @click="clickArr">数组替换</button>
</br>
前置:<input v-model="fixInx"></input>
<div v-for="item in fixStr">
<div>{{item.fixVue}}<button @click="copyClick(item.fixVue)">复制</button></div>
<div>{{item.fixJs}}<button @click="copyClick(item.fixJs)">复制</button></div>
<div>{{item.label}}<button @click="copyClick(item.label)">复制</button></div>
<div>{{item.labelPoint}}<button @click="copyClick(item.labelPoint)">复制</button></div>
<div>{{item.pla}}<button @click="copyClick(item.pla)">复制</button></div>
<div>{{item.fixCH}}<button @click="copyClick(item.fixCh)">复制</button></div>
</br>
</div>
<div style="white-space:pre">
{{arrShow}}
</div>
</div>