javascript - Why do I need to add double quotes when using es6 string template in vue's router-link?
PHP中文网
PHP中文网 2017-07-05 10:56:34
0
2
1092


I reported an error after removing the double quotes.
I don’t quite understand, please give me some advice.

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
过去多啦不再A梦

In Vue, when the HTML tag :xxx="" is included in the template, the content in the double quotes is a JS expression, not a general HTML attribute.

Example:

<p @click="count++">{{count}}</p>

At this time count++ is a piece of JS code compiled by the template and executed by Vue, rather than a simple attributed string. In the same way, what is written in router-link is also JS code, not a link string. In this way, when you need to directly return the string path, you must use single quotes to enclose the string content, such as :to="'/index'". If you write :to="/index", then Vue will evaluate a variable named /index, which is obviously illegal.

If you don’t want to nest single and double quotes, you can remove the colon and write <router-link to="/index">

滿天的星座
<router-link :to="'/dispatch/internal/treenode/'+itemSmall.view">{{ itemSmall.view }}</router-link>

Try spelling the string

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!