(jsx)在元素的文本中使用padEnd

时间:2018-08-26 11:38:37

标签: javascript html reactjs padding jsx

const text = 'testing'.padEnd(25) + 'John'

return (
    <li>{text}</li>
)

预期结果:

<li>testing                  John</li>

实际输出:

<li>testing John</li>

获得预期结果的最简单方法是什么?

与此相关:Best practice when adding whitespace in JSX 但是我应该如何进行填充呢?

1 个答案:

答案 0 :(得分:2)

您可以使用HTML标记<pre>来保持return new Router({ mode: 'history', fallback: false, scrollBehavior: () => ({ y: 0 }), routes: [ { path: '/', redirect: to => { const { params } = to if (!!params.activityType){ params.activityType = 'music' } if (!!params.city) { params.city = 'new-york' } return '/:activityType/:city' }}, { path: '/:activityType', children: [ { path: ''}, // similar redirect like from root { path: '/:city', name: 'venue-page', component: homepage, children: [ { path: '/:item', component: venue} ]} ]}, ] }) 变量周围的位置,该标记保持显示的文本。

function hasConflict($location1,$location2){
    $location1=explode(',',$location1);
    $location2=explode(',',$location2);
    if($location1[0]>=$location2[0]&&$location1[0]<=$location2[2]&&$location1[1]>=$location2[1]&&$location1[1]<=$location2[3]) return true;
    if($location2[0]>=$location1[0]&&$location2[0]<=$location1[2]&&$location2[1]>=$location1[1]&&$location2[1]<=$location1[3]) return true;
    return false;
}

$map = [
    ['0,0', '1,0', '2,0', '3,0', '4,0', '5,0', '6,0', '7,0', '8,0', '9,0'],
    ['0,1', '1,1', '2,1', '3,1', '4,1', '5,1', '6,1', '7,1', '8,1', '9,1'],
    ['0,2', '1,2', '2,2', '3,2', '4,2', '5,2', '6,2', '7,2', '8,2', '9,2'],
    ['0,3', '1,3', '2,3', '3,3', '4,3', '5,3', '6,3', '7,3', '8,3', '9,3'],
    ['0,4', '1,4', '2,4', '3,4', '4,4', '5,4', '6,4', '7,4', '8,4', '9,4'],
];

$location1 = '1,1,3,3';
$location2 = '7,0,9,1';
$location3 = '2,3,5,4';

var_dump(hasConflict($location1, $location2));// Returns false = no conflict
var_dump(hasConflict($location1, $location3));// Returns true = there is conflict
text