if (ingredients.value && content.value) {…
Jump to turn (10)
- 1if (ingredients.value && content.value) { activeChips.value.push(ingredients.val
- 2但如果此时ingredients的值中存在英文逗号也会被分割
- 3const [INCI, pct] = item.split(',')我的意思是我希望这个split可以直接分隔ingredients和content,另inc
- 4这和我的代码没区别啊,但是如果通过中文逗号进行分隔,当ingredients的值出现中文逗号就被分割了,这样如何解决
- 5那此时如果ingredients存在英文逗号它有被分割了啊
- 6activechipValues = activeChips.value.map(item => { const [INCI, pct] = item.spli
- 7它是包含多个字典的
- 8我说了多少次了如果这样的话,当ingredients的value中存在中文逗号就会被分割了
- 9不行,这样子当ingredients的值为1中文逗号3的时候,就会直接把1赋值给inci,3
- 10ingredients.value如何将这个变量的值的中文逗号全部转为英文
- User
if (ingredients.value && content.value) { activeChips.value.push(ingredients.value+","+content.value+"%"); ingredients.value = ''; content.value = ''; activechipValues = activeChips.value.map(item => { const [INCI, pct] = item.split(',') return { INCI, pct: parseFloat(pct) }; }) console.log("这是活性方案", activechipValues) }这是vue3+quasar的代码,这段代码中我是通过,来分割INCI,pct但是我发现如果INCI即ingredients中存在,就会直接被分割,忽略掉content的值
- Assistant
根据给出的代码,如果你想通过","来分割
ingredients和content,则应该在分割时使用英文逗号","而不是中文逗号","。使用
split方法时需要传递一个参数,该参数是用作分割符的字符串,以此来将目标字符串拆分为子字符串数组。所以你应该将代码中的","替换为","。这是修改后的代码:
javascript