I want to display the username as the default textarea value for markdown editor using blade syntax. <textarea v-model="message"> {{ $detailsFromLaravelContoller }}</textarea><div v-html="compiledMarkdown"></div>But I am using v-model component for the textarea which requires to declare message with an empty value like thiswindow.onload = function(){ var editor = new Vue({ el: '#editor', data: { message: '', compiledMarkdown: marked('', { sanitize: true }), }, watch: { markdown: function () { this.compiledMarkdown = marked(this.message, { sanitize: true }) } }, methods: { } })}This renders the screen with the laravel variable's value. But soon after the page loads the content disappears (as I've used window.onload I guess).Also I'm not using inline VueJS.P.S: I'm new to both VueJS and Laravel and the source for the markdown is here(jsfiddle)Thank you in advance!!! 解决方案 You are trying to pass a PHP variable value to a separate Javascript file.Here's how I would do it:Declare a global variable detailsFromLaravelContoller to store $detailsFromLaravelContoller as a string value<script> var detailsFromLaravelContoller = @json($detailsFromLaravelContoller);</script><textarea v-model="message"></textarea>use the global variable in Javascript filedata: { message: detailsFromLaravelContoller,},https://jsfiddle.net/jacobgoh101/0dzvcf4d/9954/ 这篇关于使用VueJS和Laravel的Textarea v模型初始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-04 06:31
查看更多