Javascript VueJS使用空格发送组件道具
我想从我的视图中发送组件道具,但有一个空格,它使vue返回我Javascript VueJS使用空格发送组件道具,javascript,vue.js,Javascript,Vue.js,我想从我的视图中发送组件道具,但有一个空格,它使vue返回我vendor.js:695[vue warn]:编译模板时出错:-无效表达式::user name=“Awesome” -无效表达式::user name=“Awesome” <script> export default{ props: { id: { type: String }, userNa
vendor.js:695[vue warn]:编译模板时出错:-无效表达式::user name=“Awesome”
-无效表达式::user name=“Awesome”
<script>
export default{
props: {
id: {
type: String
},
userName:{
type: String
},
main: {
type: Boolean
}
},
methods: {
setAsMain(id){
// some stuff
},
},
computed: {
mainMessage(){
return this.main == 1 ? 'Main character' : '';
}
}
}
</script>
我的看法是:
<ActionButton :id="1"
:user-name="Awesome Me"
:main="1" />
<script>
export default{
props: {
id: {
type: String
},
userName:{
type: String
},
main: {
type: Boolean
}
},
methods: {
setAsMain(id){
// some stuff
},
},
computed: {
mainMessage(){
return this.main == 1 ? 'Main character' : '';
}
}
}
</script>
<script>
export default{
props: {
id: {
type: String
},
userName:{
type: String
},
main: {
type: Boolean
}
},
methods: {
setAsMain(id){
// some stuff
},
},
computed: {
mainMessage(){
return this.main == 1 ? 'Main character' : '';
}
}
}
</script>
我的组件:
<script>
export default{
props: {
id: {
type: String
},
userName:{
type: String
},
main: {
type: Boolean
}
},
methods: {
setAsMain(id){
// some stuff
},
},
computed: {
mainMessage(){
return this.main == 1 ? 'Main character' : '';
}
}
}
</script>
<script>
export default{
props: {
id: {
type: String
},
userName:{
type: String
},
main: {
type: Boolean
}
},
methods: {
setAsMain(id){
// some stuff
},
},
computed: {
mainMessage(){
return this.main == 1 ? 'Main character' : '';
}
}
}
</script>
导出默认值{
道具:{
身份证:{
类型:字符串
},
用户名:{
类型:字符串
},
主要内容:{
类型:布尔型
}
},
方法:{
setAsMain(id){
//一些东西
},
},
计算:{
mainMessage(){
返回this.main==1?'main character':'';
}
}
}
如何发送
用户名
值由空格组成?我认为问题不在于空格,您使用的是带有道具的v-bind
或:
,而您传递的是静态数据,因此不需要这些,只需执行以下操作:
<script>
export default{
props: {
id: {
type: String
},
userName:{
type: String
},
main: {
type: Boolean
}
},
methods: {
setAsMain(id){
// some stuff
},
},
computed: {
mainMessage(){
return this.main == 1 ? 'Main character' : '';
}
}
}
</script>
<ActionButton id="1"
user-name="Awesome Me"
main="1" />
我认为问题不在于空间,您使用的是带有道具的
v-bind
或:
,而您传递的是静态数据,所以不需要这些,只需执行以下操作:
<script>
export default{
props: {
id: {
type: String
},
userName:{
type: String
},
main: {
type: Boolean
}
},
methods: {
setAsMain(id){
// some stuff
},
},
computed: {
mainMessage(){
return this.main == 1 ? 'Main character' : '';
}
}
}
</script>
<ActionButton id="1"
user-name="Awesome Me"
main="1" />
我遇到了同样的问题,并通过以下方式解决:
<script>
export default{
props: {
id: {
type: String
},
userName:{
type: String
},
main: {
type: Boolean
}
},
methods: {
setAsMain(id){
// some stuff
},
},
computed: {
mainMessage(){
return this.main == 1 ? 'Main character' : '';
}
}
}
</script>
请注意,我们必须使用另一个单引号,
我认为vue会将v-bind双引号中的任何内容解析为代码,而不是文本。
例如,如果我使用:
<script>
export default{
props: {
id: {
type: String
},
userName:{
type: String
},
main: {
type: Boolean
}
},
methods: {
setAsMain(id){
// some stuff
},
},
computed: {
mainMessage(){
return this.main == 1 ? 'Main character' : '';
}
}
}
</script>
按钮上的文本为:
<script>
export default{
props: {
id: {
type: String
},
userName:{
type: String
},
main: {
type: Boolean
}
},
methods: {
setAsMain(id){
// some stuff
},
},
computed: {
mainMessage(){
return this.main == 1 ? 'Main character' : '';
}
}
}
</script>
function() {return 'Awesome Me'}
我遇到了同样的问题,并通过以下方式解决:
<script>
export default{
props: {
id: {
type: String
},
userName:{
type: String
},
main: {
type: Boolean
}
},
methods: {
setAsMain(id){
// some stuff
},
},
computed: {
mainMessage(){
return this.main == 1 ? 'Main character' : '';
}
}
}
</script>
请注意,我们必须使用另一个单引号,
我认为vue会将v-bind双引号中的任何内容解析为代码,而不是文本。
例如,如果我使用:
<script>
export default{
props: {
id: {
type: String
},
userName:{
type: String
},
main: {
type: Boolean
}
},
methods: {
setAsMain(id){
// some stuff
},
},
computed: {
mainMessage(){
return this.main == 1 ? 'Main character' : '';
}
}
}
</script>
按钮上的文本为:
<script>
export default{
props: {
id: {
type: String
},
userName:{
type: String
},
main: {
type: Boolean
}
},
methods: {
setAsMain(id){
// some stuff
},
},
computed: {
mainMessage(){
return this.main == 1 ? 'Main character' : '';
}
}
}
</script>
function() {return 'Awesome Me'}