search
HomePHP FrameworkThinkPHPSolve the configuration problem of Thinkphp in the joint development of Thinkphp and vue

The following tutorial column of thinkphp framework will introduce to you the configuration issues of Thinkphp in the joint development of Thinkphp and vue. I hope it will be helpful to friends in need!

Solve the configuration problem of Thinkphp in the joint development of Thinkphp and vue

ThinkphpConfiguration issues of Thinkphp in joint development with vue:

1. Thinkphp returns data in json format by default

(1) Global settings - modify the Thinkphp configuration file config.php:

'default_return_type'    => 'json',

default_return_type attribute’s default value is 'html', after changing it to 'json', the data returned directly in the controller method is in json format. The global configuration is valid for all "operations" in the system

(2) Separate setting - In "Operation", return data via: return json(array, 404) (the first parameter is an array or object, and the second parameter is the status code).

return json(['name' => 'thinkphp','status' => '1'], 200);

Output data (the results of global and individual setting output are the same):

{"name":"thinkphp","status":"1"}

2. Vue request cross-domain problem

When the front and back ends are separated, vue will encounter cross-domain problems when requesting directly through axios: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Solve the configuration problem of Thinkphp in the joint development of Thinkphp and vue

You need to set the request header in "Operation"

header('Access-Control-Allow-Origin: *')

Just copy and paste it into the first line of "Operation", like this:

Solve the configuration problem of Thinkphp in the joint development of Thinkphp and vue

When you connect this "operation" through axios, you will not be prompted for cross-domain restrictions.

Solve the configuration problem of Thinkphp in the joint development of Thinkphp and vue

The above is the detailed content of Solve the configuration problem of Thinkphp in the joint development of Thinkphp and vue. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:segmentfault. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version