{"id":6226,"date":"2022-10-07T17:26:45","date_gmt":"2022-10-07T08:26:45","guid":{"rendered":"https:\/\/nsme.net\/notes\/?p=6226"},"modified":"2022-10-10T11:50:17","modified_gmt":"2022-10-10T02:50:17","slug":"sns-%e3%81%8a%e7%9f%a5%e3%82%89%e3%81%9b-vue-js-axios%e3%81%a7%e5%8f%96%e5%be%97","status":"publish","type":"post","link":"https:\/\/core.nsme.net\/notes\/site\/%e4%b8%89%e5%8d%94\/6226\/","title":{"rendered":"SNS \u304a\u77e5\u3089\u305b vue.js axios\u3067\u53d6\u5f97"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u66f8\u5eab\u3078\u79fb\u3059 \u30dc\u30bf\u30f3\u3092\u30b9\u30de\u30fc\u30c8\u306b\u8868\u793a\u3059\u308b\u305f\u3081\u5909\u66f4\u3057\u305f\u304c\u3001\u30c6\u30ad\u30b9\u30c8\u30dc\u30c3\u30af\u30b9\u306e\u8868\u793a\u304c<br>\u6539\u884c\u3092\u542b\u3081\u3084\u3084\u8868\u793a\u304c\u304a\u304b\u3057\u3044\u3002<br>PHP\u3067\u51e6\u7406\u3059\u308b\u65b9\u6cd5\u306b\u623b\u3059\u304c\u3001\u305b\u3063\u304b\u304f\u4f5c\u3063\u305f\u306e\u3067\u3053\u3053\u306b\u4fdd\u7ba1\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;section id=\"notice\"&lt;?php if(! $editor) { echo ' style=\"max-height:none\"'; } ?&gt;&gt;\n   &lt;h3 class=\"baner_title\"&gt;\u304a\u3057\u3089\u305b&lt;\/h3&gt;\n&lt;ul&gt;\n  &lt;li v-for=\"list in oshirase\" v-bind:class=\"list.class\"&gt;\n    &lt;div v-html=\"list.content\"&gt;&lt;\/div&gt;\n    \n    &lt;footer class=\"entry-meta\"&gt;\n    &lt;div v-if=\"list.author_id ==user_id || user_id ==1\" style=\"display: inline\"&gt;\n        &lt;a v-bind:href=\"'.\/wp-admin\/post.php?post=' + list.id + '&amp;action=edit'\"&gt;\u7de8\u96c6 &lt;\/a&gt;\n        &lt;button v-on:click=\"moveOshirase(list.id)\" class=\"abutton\"&gt;\u66f8\u5eab\u3078\u79fb\u3059&lt;\/button&gt;\u3000\n        &lt;button class=\"abutton\" v-on:click=\"deleteOshirase(list.id)\"&gt;\u524a\u9664&lt;\/button&gt;\u3000\n      &lt;\/div&gt;\n      {{ list.post_date }}\u3000{{ list.author_name }}\n    &lt;\/footer&gt;\n  &lt;\/li&gt;\n&lt;\/ul&gt;\n   &lt;\/section&gt;\n\n\n\n   const app = new Vue({\n   \tel :'#content',\n   \tdata : {\n   \t\toshirase: &#91;],\n   \t},\n     created(){\n   \t\tthis.getOshirase();\n   \t},\n\n   \tmethods: {\n   \t\tgetOshirase(){\n   \t\t  axios.get('&lt;?php echo home_url(); ?&gt;\/axios',\n   \t\t\t\t { params:{\n   \t\t\t\t\t get: 'notice',\n   \t\t\t\t\t user_id : this.user_id,\n   \t\t\t\t\tusercatid : this.usercatid\n   \t\t\t\t }\n   \t\t\t\t})\n             .then(response =&gt; this.oshirase = response.data)\n             .catch(response =&gt; console.log(response))\n   \t\t},\n\n   \t\tmoveOshirase(id){\n   \t\t\tfetch(\"&lt;?php echo home_url(); ?&gt;\/fetch?move_notice&amp;id=\" + id)\n   \t\t\t\t.then(response =&gt; {\n   \t\t\t\t\t\treturn response.json(); \n   \t\t\t\t})\n   \t\t\t\t.then(data =&gt; { \n   \t\t\t\t\tthis.getOshirase();\n   \t\t\t\t})\n   \t\t\t\t.catch(error =&gt; { \n   \t\t\t\t\t\tconsole.log(error);\n   \t\t\t\t})\n   \t\t},\n   \t\tdeleteOshirase(id){\n   \t\t\tlet check = confirm('\u3053\u306e\u304a\u77e5\u3089\u305b\u3092\u672c\u5f53\u306b\u524a\u9664\u3057\u307e\u3059\u304b\uff1f');\n   \t\t\tif(check){\n   \t\t\t\tfetch(\"&lt;?php echo home_url(); ?&gt;\/fetch?delete_notice&amp;id=\" + id)\n   \t\t\t\t\t.then(response =&gt; {\n   \t\t\t\t\t\t\treturn response.json(); \n   \t\t\t\t\t})\n   \t\t\t\t\t.then(data =&gt; { \n   \t\t\t\t\t\tthis.getOshirase();\n   \t\t\t\t\t})\n   \t\t\t\t\t.catch(error =&gt; { \n   \t\t\t\t\t\t\tconsole.log(error);\n   \t\t\t\t\t})\n   \t\t\t}\n   \t\t},   \t\t\n\n   \t}\n   })\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">axios.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if($_GET&#91;'get']=='notice'){\n\t$user_id = $_GET&#91;'user_id'];\n\t$usercatid = $_GET&#91;'usercatid'];\n\t\n\t\/\/\u691c\u7d22\u304c\u65e9\u304f\u306a\u308b\u3088\u3046\u306b\u30bf\u30b0\u3067\u306f\u306a\u304fComments\u30b9\u30c6\u30fc\u30bf\u30b9\u3067\u306e\u5206\u985e\u306b\u5909\u66f4\n$sql = \"SELECT ID,post_author,post_date,post_content,post_title FROM wp_posts\nWHERE post_type='notice' AND post_status='publish' AND comment_status='open' ORDER BY post_date DESC\";\n$results = $wpdb->get_results($sql);\n$res = array();\n\t\nforeach ($results as $key=>$val){\n\t$id = $val->ID;\n\t$authordata = get_userdata($val->post_author);\n\t$author_login = $authordata->user_login;\n\t$author_name = $authordata->display_name;\n\t\n\t  $staff= get_post_meta($id, 'notice_staff', true);\n\t\tif($staff !='') {\n\t\t  \/\/\u901a\u77e5\u8005\u306b\u6295\u7a3f\u8005\u3092\u8ffd\u52a0\n\t\t  \/\/\u30ab\u30c6\u30b4\u30ea\u30fc\u30b9\u30e9\u30c3\u30b0\u304b\u3089\u30ab\u30c6\u30b4\u30ea\u30fcID\u3092\u53d6\u5f97\n\t\t\t$author_cat=get_category_by_slug($author_login);\n\t\t\t$author_catid= $author_cat ->cat_ID;\n\t\t  array_push($staff, $author_catid);\n\t  }else{\n\t\t\t$staff = array();\n\t\t}\n\t\n\t $select = get_field('notice_selet',$id);\n\t\t\t\n if($select==='\u5168\u793e\u54e1' || array_key_exists($usercatid,array_flip($staff)) || array_key_exists($user_id,array_flip($officer))) {\n\t if($select=='\u5168\u793e\u54e1') {\n\t\t $res&#91;$key]&#91;'class'] = 'allstaff';\n\t }else{\n\t\t $res&#91;$key]&#91;'class'] = 'selectstaff';\n\t }\n\t $content = preg_replace(\"\/(&lt;&#91;a-zA-Z0-9=\\\"\\\/\\ ]+>)&lt;br\\ \\\/>\/\", \"$1\", nl2br($val->post_content));\n\t \n\t \n\t if($val->post_title !=''){\n\t\t  $res&#91;$key]&#91;'content'] = '&#91; '. $val->post_title .' ]&lt;br>'.$content;\n\t }\n\t else{\n\t\t  $res&#91;$key]&#91;'content'] = $content;\n\t }\n\t $res&#91;$key]&#91;'id'] = $id;\n\t $res&#91;$key]&#91;'author_id'] = $val->post_author;\n\t $res&#91;$key]&#91;'author_name'] = $author_name;\n\t $res&#91;$key]&#91;'post_date'] = date('Y\/m\/d', strtotime($val->post_date));\n\t \n\t }\n}\n\techo json_encode($res);\n\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u66f8\u5eab\u3078\u79fb\u3059 \u30dc\u30bf\u30f3\u3092\u30b9\u30de\u30fc\u30c8\u306b\u8868\u793a\u3059\u308b\u305f\u3081\u5909\u66f4\u3057\u305f\u304c\u3001\u30c6\u30ad\u30b9\u30c8\u30dc\u30c3\u30af\u30b9\u306e\u8868\u793a\u304c\u6539\u884c\u3092\u542b\u3081\u3084\u3084\u8868\u793a\u304c\u304a\u304b\u3057\u3044\u3002PHP\u3067\u51e6\u7406\u3059\u308b\u65b9\u6cd5\u306b\u623b\u3059\u304c\u3001\u305b\u3063\u304b\u304f\u4f5c\u3063\u305f\u306e\u3067\u3053\u3053\u306b\u4fdd\u7ba1\u3002 axios.php<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[54],"tags":[],"class_list":["post-6226","post","type-post","status-publish","format-standard","hentry","category-54"],"acf":[],"_links":{"self":[{"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/posts\/6226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/comments?post=6226"}],"version-history":[{"count":2,"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/posts\/6226\/revisions"}],"predecessor-version":[{"id":6228,"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/posts\/6226\/revisions\/6228"}],"wp:attachment":[{"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/media?parent=6226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/categories?post=6226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/core.nsme.net\/notes\/wp-json\/wp\/v2\/tags?post=6226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}