发布:2022/3/24 17:25:37作者:管理员 来源:本站 浏览次数:928
<template>
<div>
<p>自动检测中英文</p>
<p>{{msg}}</p>
<p>
<textarea v-model="texts"></textarea>
</p>
<p>
<textarea v-model="textsed"></textarea>
</p>
<p>
<input type="button" v-on:click="getProduct" value="翻译" >
</p>
</div>
</template>
<script>
import axios from 'axios'// 引入axios
import App from '../App.vue'
export default {
components: { App },
data: function () {
return {
msg: '',
texts: '',
textsed: ''
}
},
methods: {
getProduct () {
let _this = this
axios.get('http://api.microsofttranslator.com/V2/Ajax.svc/TranslateArray?oncomplete=jQuery19102471454823155229_1648110034885&from=zh-CHS&to=en&appId=TK3TNgyW9E_DF5vzwUyDFejFfyRxYW-UpjpC842fei9k*&texts=["' + _this.texts + '"]&_=1648110034936').then(
function (data) {
console.log('*************成功getMessage*************')
console.log(data)
_this.msg = data.data
var obj = data.data
var _str = obj.substring(0, obj.length - 1).replace('jQuery19102471454823155229_1648110034885', '').replace('([{', '').replace('}])', '')
console.log(_str)
// eslint-disable-next-line camelcase
var _str_1 = _str.split(',')
// eslint-disable-next-line camelcase
var _str_2 = _str_1[2]
// eslint-disable-next-line camelcase
var _str_3 = _str_2.split(':')
console.log(_str_3[1])
// eslint-disable-next-line no-useless-escape
_this.textsed = _str_3[1].replace(/\"/g, '')
},
function (data) {
console.log(data)
}
)
}
},
// vue生命周期函数
mounted () {
// this.getProduct()
}
}
</script>
<style lang="sss">
</style>
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4