Javascript 如何在html属性中写入Vue数据?

Javascript 如何在html属性中写入Vue数据?,javascript,vue.js,Javascript,Vue.js,例如,这将引发Vue错误: <img src="<?php echo get_stylesheet_directory_uri(); ?>/images/{{ form.screw.drive_image }}" > /images/{{form.screw.drive_image}}> 我正在src prop中编写{{form.screw.drive\u image} Vue的警告并不清楚我应该如何解决 有什么想法吗?你应该使用 <img v-bind:src

例如,这将引发Vue错误:

<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/{{ form.screw.drive_image }}" >
/images/{{form.screw.drive_image}}>
我正在src prop中编写
{{form.screw.drive\u image}

Vue的警告并不清楚我应该如何解决

有什么想法吗?

你应该使用

<img v-bind:src="form.screw.drive_image" />

并将form.screw.drive\u image的值更改为包含get\u stylesheet\u directory\u uri()

:src="'<?= get_stylesheet_directory_uri(); ?>/images/' + form.screw.drive_image"
:src=“'/images/'+form.screw.drive\u image”
请注意以下事项:

  • :src
    是v-bind:src
  • 您可以使用文档中的:

    将一个或多个属性或组件属性动态绑定到表达式

    格式:

    <img :src="'some_string' + some_data">
    
    
    
    最终产品:

    <img :src="'<?=get_stylesheet_directory_uri(); ?>/images/' + form.screw.drive_image">
    
    /images/'+form.screw.drive\u image>
    
    什么是错误警告?一个通用的[Vue warn]:编译模板时出错
    :src=“'/images/'+form.screw.drive_image”>
    @Derek有效谢谢。同时提醒您,Vue模板
    {…}
    绑定在属性中不起作用,您需要使用
    /
    v-bind:
    快捷方式来表示需要对静态字符串进行计算/解析的属性。