2

marginTop: '${this.inputMarginTop}%'

Как мне вставить переменную равную числу, в marginTop в процентах

style={{marginLeft: 10, marginBottom: 8, marginTop: '${this.inputMarginTop}%'}}

this.inputMarginTop есть, выводил в консоль

1 ответ 1

2

Для использования template literal Нужно использовать другой вид кавычек:

`${this.inputMarginTop}%`

В противном случае будет обычная строка без подстановки.

Пример:

var inputMarginTop = 10;
console.log('${inputMarginTop}%');
console.log(`${inputMarginTop}%`);

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.