I'm trying a demo on vuejs. Now I want the html title to bind a vm field.
The below is what I tried:
index.html
<!DOCTYPE html>
<html id="html">
<head>
<title>{{ hello }}</title>
<script src="lib/requirejs/require.min.js" data-main="app"></script>
</head>
<body>
{{ hello }}
<input v-model="hello" title="hello" />
</body>
</html>
app.js
define([
'jquery', 'vue'
], function ($, Vue) {
var vm = new Vue({
el: 'html',
data: {
hello: 'Hello world'
}
});
});
But the title seemed not bounded, how to make it work?
You can do it with 1 line in the App.vue file, like this:
Or change the
<title>
tag content inpublic/index.html
As I prefer to set the
<title>
from the view part, there are essentially two ways to solve it.Use an existing Component
For example, vue-headful:
Note that vue-headful not only supports the title, but also several meta tags and the document language.
Create your own Component
Create a vue file containing:
Register the component using
Then you can use it in your views, e.g.
Title and meta tags can be edited and updated asynchronously.
You can use state management, create a store for SEO using vuex and update each part accordingly.
Or you can update the element by yourself easily
This answer is for vue 1.x
using requirejs.
you can do it like this using the ready function to set the initial value and watch to update when the data changes.
also i tried this based on your original code and it works