Vue+Springboot project report: Not allowed to load local resource

I haven't written a vue project for a long time, and I wrote and reported this error again.
In fact, it is the protection of the browser, which prevents direct access to files on the local disk.

Step 1: Create a configuration class on the back end and implement the WebMvcConfigurer interface

package Router.common;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
@Configuration
public class MyConfigurer implements WebMvcConfigurer {
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/image/**").addResourceLocations("file:D:/img/");
  }
}

Fill in the virtual path you want to set in the first addResourceHandler method, and
fill in the absolute path of the resource in the addResourceLocations method below. After the configuration is complete, the virtual path is
http://localhost:configuration class port number/doctor/picture name.

Step 2: Front-end configuration path

 data() {
        return {
            rodeList:[],
            radio:false,
            checked:[],
            typeList:[],
            url:"http://localhost:8080/image/"
        }
    },
    ```

<td><img  :src="url+router.position" alt="" >

Guess you like

Origin blog.csdn.net/weixin_48143996/article/details/128833294