尊龙凯时人生就是搏

vueÏîÄ¿Ôõô¸úthinkphpÍŽá

vueÊÇÒ»ÖÖÏÖ´ú»¯µÄjavascript¿ò¼Ü £¬ÓÃÓÚ¹¹½¨»¥¶¯ÐÔÇ¿µÄwebÓ¦ÓóÌÐò¡£¶øthinkphpÔòÊǺ£ÄÚ×ÅÃûµÄphp¿ªÔ´¿ò¼Ü £¬¿ÉÒÔ×ÊÖú¿ª·¢Õß¿ìËÙ¹¹½¨¸ßЧ¡¢¸ßÖÊÁ¿µÄwebÓ¦ÓóÌÐò¡£ÔÚÏÖʵ¿ª·¢ÖÐ £¬vueºÍthinkphp¾­³£±»Í¬Ê±Ê¹Óà £¬Òò´Ë½«¶þÕßÍŽáÆðÀ´ÊǼ«Îª³£¼ûµÄÐèÇó¡£

±¾ÆªÎÄÕ½«ÏÈÈÝVueºÍThinkPHPµÄ»ù±¾¿´·¨¼°ÔõÑù½«¶þÕßÍŽáʹÓá£ÈôÊÇÄãÒѾ­ÊìϤÁËVueºÍThinkPHPµÄ»ù±¾ÖªÊ¶ £¬ÄÇô¿ÉÒÔÖ±½ÓÌøÖÁÒÔÏÂÕ½ڣº

VueÏîÄ¿ÓëThinkPHPÍŽᡪ¡ªÇ°ºó¶ËÊèɢģʽ

Ç°¶ËÔõÑùŲÓÃThinkPHP½Ó¿Ú

ThinkPHPÈçÄÇÀïÖýӿÚÇëÇó

×ܽá

VueÏîÄ¿ÓëThinkPHPÍŽᡪ¡ªÇ°ºó¶ËÊèɢģʽ

VueÊÇÒ»ÖÖÇ°¶Ë¿ò¼Ü £¬ÓÃÓÚ¹¹½¨Óû§½çÃæ¡£¶øThinkPHPÔòÊÇÒ»ÖÖºó¶Ë¿ò¼Ü £¬ÓÃÓÚ¹¹½¨WebÓ¦ÓóÌÐòµÄЧÀÍÆ÷¶Ë¡£Òò´Ë £¬Ç°¶ËVueÏîÄ¿ºÍºó¶ËThinkPHPÓ¦ÓóÌÐòµÄÍŽá £¬Í¨³£½ÓÄÉÇ°ºó¶ËÊèɢģʽ¡£

Ç°ºó¶ËÊèɢģʽµÄ»ù±¾Ë¼Ð÷ÊÇ £¬½«Ç°¶ËVueÏîÄ¿Óëºó¶ËThinkPHPÓ¦ÓóÌÐòÊèÉ¢¿ªÀ´ £¬Á½Õßͨ¹ýAPI¾ÙÐÐͨѶ¡£VueÏîÄ¿ÈÏÕæÌṩÓû§½çÃæºÍ½»»¥Âß¼­ £¬ThinkPHPÓ¦ÓóÌÐòÔòÈÏÕæ´¦ÀíÊý¾Ý¡¢Âß¼­¡¢È¨Ï޵Ⱥǫ́´¦Àí¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

Ç°ºó¶ËÊèɢģʽµÄÓŵãÔÚÓÚ £¬¿ÉÒÔ½«Ç°ºó¶Ë¿ª·¢ÊÂÇé»®·Ö·Ö¸øרÃŵÄÖ°Ô±¡£Ç°¶Ë¿ª·¢Ö°Ô±¿ÉÒÔרעÓÚ¹¹½¨Óû§½çÃæºÍ½»»¥Âß¼­ £¬´Ëºó¶Ë¿ª·¢Ö°Ô±¿ÉÒÔרעÓÚ´¦ÀíÊý¾ÝºÍÂß¼­ÎÊÌâ¡£ÕâÑù £¬¿ÉÒÔÌá¸ß¿ª·¢Ð§ÂÊ £¬Í¬Ê±Ò²¿ÉÒÔ±ãÓÚά»¤ºÍÀ©Õ¹¡£

ÔÚÏÖʵ¿ª·¢ÖÐ £¬Ç°ºó¶ËÊèɢģʽµÄÏêϸʵÏÖ·½·¨ÓжàÖÖ £¬ÏÂÃæÊÇÒ»ÖÖ½ÏÁ¿µä·¶µÄ¼Æ»®£º

Ê×ÏÈ £¬ÎÒÃÇÐèÒªÔÚЧÀÍÆ÷¶Ë½¨ÉèÒ»¸öThinkPHPÓ¦ÓóÌÐò £¬ÓÃÓÚ½ÓÊÜÇ°¶ËVueÏîÄ¿·¢Ë͵ÄÇëÇó £¬²¢¾ÙÐÐÏìÓ¦µÄ´¦Àí¡£¿ÉÒÔÔÚThinkPHPµÄ¿ØÖÆÆ÷ÖбàдÏìÓ¦µÄ´¦Àí´úÂë¡£

½Ó×Å £¬ÔÚÇ°¶ËVueÏîÄ¿ÖÐ £¬ÎÒÃÇÐèҪʹÓÃVue Resource»òAxiosµÈHTTPÇëÇó¿â £¬Ïòºó¶Ë·¢ËÍÇëÇó £¬²¢´¦ÀíÏìÓ¦Êý¾Ý¡£¿ÉÒÔÔÚVue×é¼þÖбàдÏìÓ¦µÄÇëÇóºÍ´¦Àí´úÂë¡£

×îºó £¬½«VueÏîÄ¿ºÍThinkPHPÓ¦ÓóÌÐò°²ÅÅÔÚ²î±ðµÄЧÀÍÆ÷ÉÏ £¬Í¨¹ýAPI¾ÙÐÐͨѶ £¬Ê¹Ç°ºó¶Ë½»»¥Íê³É¡£

Ç°¶ËÔõÑùŲÓÃThinkPHP½Ó¿Ú

ÔÚÇ°¶ËVueÏîÄ¿ÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃVue Resource»òAxiosµÈHTTPÇëÇó¿â £¬Ïòºó¶ËThinkPHPÓ¦ÓóÌÐò·¢ËÍÇëÇó¡£

ÒÔAxiosΪÀý £¬ÎÒÃÇ¿ÉÒÔÔÚVue×é¼þÖбàдÈçÏ´úÂ룺

import axios from 'axios'
export default {
  data () {
    return {
      message: ''
    }
  },
  methods: {
    getMessage () {
      axios.get('/api/getMessage').then(response => {
        this.message = response.data.message
      })
    }
  }
}

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖÐ £¬ÎÒÃÇÒýÈëÁËAxios¿â £¬²¢ÔÚVue×é¼þÖнç˵ÁËÒ»¸öÒªÁìgetMessage¡£Õâ¸öÒªÁì·¢ËÍÒ»¸öGETÇëÇó/api/getMessageÖÁºó¶ËThinkPHPÓ¦ÓóÌÐò £¬»ñÈ¡·µ»ØµÄÊý¾Ý £¬È»ºó½«·µ»ØµÄÐÂÎÅ´æ´¢ÔÚ×é¼þµÄdataÖС£

ÐèҪעÖصÄÊÇ £¬/api²¿·ÖÔÚÏÖʵ¿ª·¢ÖпÉÄÜ»áÓÐËù²î±ð £¬Ïêϸƾ֤Äã×Ô¼ºµÄÏîÄ¿ÉèÖöø¶¨¡£¸Ã²¿·Öͨ³£ÓÃÓÚ±êʶAPIµÄÈë¿Ú £¬ÌåÏÖÕâÊÇÒ»¸öAPIÇëÇó £¬¶ø²»ÊÇͨË×µÄÒ³ÃæÇëÇó¡£

ÀàËƵØ £¬ÎÒÃÇÒ²¿ÉÒÔʹÓÃAxios·¢ËÍPOSTÇëÇó¡¢PUTÇëÇóµÈÆäËüÀàÐ͵ÄÇëÇó¡£ÏêϸҪÁìºÍ²ÎÊý¿ÉÒԲο¼AxiosÎĵµ¡£

ThinkPHPÈçÄÇÀïÖýӿÚÇëÇó

ÔÚºó¶ËThinkPHPÓ¦ÓóÌÐòÖÐ £¬ÎÒÃÇ¿ÉÒÔ±àд¿ØÖÆÆ÷À´´¦ÀíÇ°¶ËVueÏîÄ¿·¢Ë͵ÄÇëÇó¡£

Ê×ÏÈ £¬ÐèÒªÔÚ·ÓÉÎļþÖÐÉèÖÃAPI·ÓÉ £¬½«APIÇëÇóת·¢µ½ÏìÓ¦µÄ¿ØÖÆÆ÷¡£

use thinkRoute;
Route::group('api', function () {
    Route::get('getMessage', 'api/MessageController/getMessage');
});

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖÐ £¬ÎÒÃÇʹÓÃÁËThinkPHPµÄ·Óɹ¦Ð§ £¬½«GETÇëÇó/api/getMessageת·¢µ½MessageControllerµÄgetMessageÒªÁìÀï¡£ÎÒÃÇ»¹¿ÉÒÔÔÚ·ÓÉÎļþÖÐÉèÖÃÆäËüÀàÐ͵ÄÇëÇó £¬ÈçPOST¡¢PUTµÈÀàÐÍÇëÇóµÄ·ÓÉ¡£

½Ó×Å £¬ÔÚMessageControllerÖÐ £¬ÎÒÃÇ¿ÉÒÔ±àдgetMessageÒªÁìÀ´´¦ÀíÇ°¶ËVueÏîÄ¿·¢Ë͵ÄÇëÇó¡£ÏÂÃæÊÇÒ»¸öÀý×Ó£º

namespace apppicontroller;
use thinkController;
class MessageController extends Controller {
    public function getMessage() {
        $message = 'Hello, Vue! This is a message from ThinkPHP.';
        return ['message' => $message];
    }
}

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖÐ £¬ÎÒÃǽ¨ÉèÁËÒ»¸öÃûΪMessageControllerµÄ¿ØÖÆÆ÷ £¬½ç˵ÁËgetMessageÒªÁì¡£¸ÃÒªÁì·µ»ØÒ»¸öÊý×é £¬ÆäÖаüÀ¨ÁËÒ»¸öÃûΪmessageµÄÐÂÎÅ £¬¸ÃÐÂÎŽ«×÷ΪÏìÓ¦Êý¾Ý·¢ËÍÖÁÇ°¶Ë¡£

ÔÚÏÖʵ¿ª·¢ÖÐ £¬ÎÒÃÇ¿ÉÒÔƾ֤×Ô¼ºµÄÐèÇó £¬ÔÚ¿ØÖÆÆ÷ÖбàдÏìÓ¦µÄÊý¾Ý´¦ÀíÂß¼­¡£ÀýÈç £¬ÎÒÃÇ¿ÉÒÔ¶ÁÈ¡Êý¾Ý¿â¡¢²Ù×÷SessionµÈ £¬½«´¦ÀíЧ¹ûÒÔJSONÃûÌ÷µ»Ø¸øÇ°¶Ë¡£

×ܽá

±¾ÎÄÏÈÈÝÁËÔõÑù½«Ç°¶ËVueÏîÄ¿ºÍºó¶ËThinkPHPÓ¦ÓóÌÐòÍŽáʹÓà £¬½ÓÄÉÁËÇ°ºó¶ËÊèɢģʽ¡£

ÏêϸÀ´Ëµ £¬ÎÒÃÇÒÔAxiosΪÀý £¬ÑÝʾÁËÔõÑùÔÚÇ°¶ËVueÏîÄ¿ÖÐʹÓÃAxios·¢ËÍHTTPÇëÇóÖÁºó¶ËThinkPHPÓ¦ÓóÌÐò £¬²¢ÀֳɻñÈ¡Á˺ó¶Ë´¦ÀíºóµÄÏìÓ¦Êý¾Ý¡£

ÔÚºó¶ËThinkPHPÓ¦ÓóÌÐòÖÐ £¬ÎÒÃÇʹÓÃÁË·Óɹ¦Ð§ºÍ¿ØÖÆÆ÷ £¬ÈÏÕæÎüÊպʹ¦ÀíÀ´×ÔÇ°¶ËVueÏîÄ¿·¢Ë͵ÄÇëÇó £¬²¢½«´¦ÀíЧ¹ûÒÔJSONÃûÌ÷µ»Ø¸øÇ°¶Ë¡£

ËäÈ» £¬²¢²»¾ÖÏÞÓÚ±¾ÎÄËùÏÈÈݵļƻ® £¬ÉÐÓÐÆäËüÐí¶àÖÖʵÏÖÇ°ºó¶ËÊèÉ¢µÄ¼Æ»®¡£Ï£ÍûÕâƪÎÄÕ¿ÉÒÔ×ÊÖúÄã¸üÇáËɵØʵÏÖVueÏîÄ¿ÓëThinkPHPµÄÍŽá¡£

ÒÔÉϾÍÊÇvueÏîÄ¿Ôõô¸úthinkphpÍŽáµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ