在vue2中 我的this.request.queueName为aaa||123.123,我现在要把这个字符串拆分了 前面的aaa作为this.request.queueName,后面的123.123作为this.request.serverIp 怎么写代码
时间: 2024-03-06 11:47:33 浏览: 25
你可以使用JavaScript的字符串分割函数`split()`来实现这个功能。具体代码如下:
```
let str = this.request.queueName;
let arr = str.split('||');
this.request.queueName = arr[0];
this.request.serverIp = arr[1];
```
这样就可以将字符串按照`||`分割成两个部分,然后分别赋值给`this.request.queueName`和`this.request.serverIp`。
相关问题
在vue2中 我的this.request.queueName一个列表里面的元素为aaa||123.123这样的格式,我现在要把这个列表里面的字符串拆分再组成两个新列表 前面的aaa作为this.request.queueName列表里的元素,后面的123.123作为this.request.serverIp列表里的元素 怎么写代码
您可以使用 JavaScript 的 split() 函数将字符串拆分成两个部分,然后将它们分别添加到两个新的数组中。以下是可能的代码实现:
```javascript
let queueNames = [];
let serverIps = [];
this.request.queueName.forEach(item => {
let parts = item.split('||');
queueNames.push(parts[0]);
serverIps.push(parts[1]);
});
this.request.queueName = queueNames;
this.request.serverIp = serverIps;
```
这里使用 forEach() 函数遍历了原始的列表,然后对每个元素使用 split() 函数将其拆分成两部分。然后将这两个部分分别添加到两个新的数组中。最后,将这两个新数组分别赋值给 this.request.queueName 和 this.request.serverIp。
vue2中this.$vm.$set为undefined
在 Vue 2 中,`this.$vm.$set` 是 undefined 是因为 `$set` 这个方法并不存在于 Vue 实例中。`$set` 方法是用于在 Vue 中以响应式地方式设置对象属性的。在 Vue 2 中,可以使用 `Vue.set` 方法来实现同样的效果。
你可以将代码中的 `this.$vm.$set` 替换为 `Vue.set`,并传递对象、要设置的属性和对应的值作为参数。例如:
```javascript
Vue.set(this.$vm, 'propertyName', propertyValue);
```
这样就可以在 Vue 2 中实现类似于 `this.$vm.$set` 的功能了。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![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_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)
![](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)